SQL help in resultant table
I am doing my Bsc IT major project and i am doing Cinema Ticketing System i have 3 tables
movies
movieID movieName ticketPrice
1001 3 idiots 200
1002 ready 300
1003 robot 250
schedule
showId movieId
9001 1001
9002 1003
9003 1002
tickets
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
i want to get the following result
userName showId TotalAmount(Product of Count(TicketNo) and ticketPrice)
A 9001 1200
A 9002 500
B 9001 400
B 9003 600
pls help me
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
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
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` ;
Just a thought: In many places it is customary to have different prices in a cinema not only because of the movie, but because of the time the movie is playing (i.e. mornings are cheaper, weekend evenings are more expensive). If you want to take this into consideration, then you shouldn't link the price to a movie, but to a show.
精彩评论