我正在做我的Bsc IT主要项目,我正在做电影票务系统 我有3张桌子
影
movieID movieName ticketPrice
1001 3 idiots 200
1002 ready 300
1003 robot 250
时间表
showId movieId
9001 1001
9002 1003
9003 1002
票
ticketNo showId soldBy
21 9001 A
73 9001 B
23 9001 A
22 9001 A
64 9002 A
34 9003 B
11 9001 A
98 9001 A
38 9003 B
78 9001 B
24 9002 A
31 9001 A
我想得到以下结果
userName showId TotalAmount(Product of Count(TicketNo) and ticketPrice)
A 9001 1200
A 9002 500
B 9001 400
B 9003 600
请帮帮我
答案 0 :(得分:2)
SELECT
t.soldBy AS userName,
t.showId,
SUM(m.ticktPrice) AS TotalAmount
FROM
tickets t
INNER JOIN schedule s ON s.showId = t.showId
INNER JOIN movies m ON m.movieId = s.movieId
GROUP BY
t.soldBy,
t.showId
答案 1 :(得分:1)
select t.soldBy userName, t.showId showId, count(t.ticketNo) * m.tickeprice total
from tickets t
inner join schedule s on t.showId = s.showId
inner join movies m on m.movieId = s.movieId
group by t.soldBy, t.showId
答案 2 :(得分:0)
SELECT
T.`soldBy`,
T.`showId`,
SUM(M.`ticketPrice`)
FROM
tickets AS T
INNER JOIN schedule AS S
ON T.`showId` = S.`showId`
INNER JOIN movies AS M
ON S.`movieID` = M.`movieID`
GROUP BY T.`soldBy`,
T.`showId` ;
只是一个想法:在许多地方习惯于在电影院中有不同的价格,不仅因为电影,而且因为电影播放的时间(即早晨更便宜,周末晚上更贵)。如果你想考虑到这一点,那么你不应该将价格与电影联系起来,而应该与节目相关联。