各階層的盈利能力......
select ytt.YogaID,
ytt.Day,
ytt.StartTime,
ytt.RoomNum,
yt.ClassPrice,
ifnull(ytt.Duration,0) as Duration,
ifnull(yr.CostPerHour,0) as CostPerHour,
ifnull(yr.RoomCapacity,0) as RoomCapacity,
round( ifnull(yr.RoomCapacity,0)*yt.ClassPrice
- (ifnull(yr.CostPerHour,0)*ifnull(ytt.Duration,0)/60)
, 2) as Profitability
from YogaTypes yt
left join YogaTimeTable ytt on (ytt.YogaID=yt.YogaID)
left join YogaRooms yr on (yr.RoomNum=ytt.RoomNum);
+--------+-----------+-----------+---------+------------+----------+-------------+--------------+---------------+
| YogaID | Day | StartTime | RoomNum | ClassPrice | Duration | CostPerHour | RoomCapacity | Profitability |
+--------+-----------+-----------+---------+------------+----------+-------------+--------------+---------------+
| DRU | Wednesday | 10:30:00 | 1 | 18.50 | 60.00 | 100.00 | 20 | 270.00 |
| DRU | Tuesday | 17:00:00 | 2 | 18.50 | 90.00 | 50.00 | 10 | 110.00 |
| SUN | Monday | 07:30:00 | 3 | 18.00 | 60.00 | 150.00 | 25 | 300.00 |
| HAT | Tuesday | 07:30:00 | 4 | 20.00 | 90.00 | 70.00 | 15 | 195.00 |
| HAT | Monday | 18:30:00 | 4 | 20.00 | 60.00 | 70.00 | 15 | 230.00 |
| NULL | NULL | NULL | NULL | 17.00 | 0.00 | 0.00 | 0 | 0.00 |
+--------+-----------+-----------+---------+------------+----------+-------------+--------------+---------------+
6 rows in set (0.00 sec)
的利潤低於預期的類別...
select ytt.YogaID,
ytt.Day,
ytt.StartTime,
ytt.RoomNum
from YogaTypes yt
left join YogaTimeTable ytt on (ytt.YogaID=yt.YogaID)
left join YogaRooms yr on (yr.RoomNum=ytt.RoomNum)
where ifnull(yr.RoomCapacity,0)*yt.ClassPrice
- (ifnull(yr.CostPerHour,0)*ifnull(ytt.Duration,0)/60) < 200;
+--------+---------+-----------+---------+
| YogaID | Day | StartTime | RoomNum |
+--------+---------+-----------+---------+
| DRU | Tuesday | 17:00:00 | 2 |
| HAT | Tuesday | 07:30:00 | 4 |
| NULL | NULL | NULL | NULL |
+--------+---------+-----------+---------+
3 rows in set (0.00 sec)
現在刪除不需要的rable sessions ...
delete tt.*
from YogaTimeTable tt,
(select ytt.YogaID,
ytt.Day,
ytt.StartTime,
ytt.RoomNum
from YogaTypes yt
left join YogaTimeTable ytt on (ytt.YogaID=yt.YogaID)
left join YogaRooms yr on (yr.RoomNum=ytt.RoomNum)
where ifnull(yr.RoomCapacity,0)*yt.ClassPrice
- (ifnull(yr.CostPerHour,0)*ifnull(ytt.Duration,0)/60) < 200
) as unprof
where tt.YogaID=unprof.YogaID
and tt.RoomNum=unprof.RoomNum
and tt.Day=unprof.Day
and tt.StartTime=unprof.StartTime;
Query OK, 2 rows affected (0.00 sec)
初次腮紅你有3個表被加入到子查詢中,但只有一個表連接標準。如果你使用內連接語法和''''符號,這將更加明顯,這樣的疏忽不會被錯過。具體來說,你說r和t如何關聯'r.roomnum = tt.roomnum',但你沒有說明如何但不是r和t或tt和t關聯 – xQbert
從YogaTimeTable中選擇*; 從YogaTimeTable 刪除 凡RoomNum IN(來自YogaRooms R, YogaTypes噸, YogaTimeTable選擇tt.RoomNum TT 其中r.RoomNum = tt.roomNum和tt.YogaID = t.YogaID 和((R。 RoomCapacity * t.ClassPrice) - (r.CostPerHour * tt.duration/60))<200); 從YogaTimeTable中選擇*; – Obi
我加入其他兩個表後結果是一樣的,它刪除了錯誤的類...... – Obi