在MySql中,我从这两个查询中获得了2个列表/表。表1包含一种票证的数量,表2包含一种票证的价格。
表1:
SELECT Count(`ticket`.`Ticket_type`) AS Counter
FROM `ticket`
WHERE ((`ticket`.`Ticket_type` = 'Adult') OR (`ticket`.`Ticket_type` = 'Senior'))
GROUP BY `ticket`.`Ticket_type`
表2:
SELECT `ticketprice`.`price`
FROM `ticketprice`
WHERE ((`ticketprice`.`Ticket_type` = 'Adult') OR (`ticketprice`.`Ticket_type` = 'Senior'))
我的问题是如何将这两个表相乘? (Qunatity * Price) = Total
会感谢任何帮助!
答案 0 :(得分:2)
加入表格并乘以:
SELECT t.ticket_type, COUNT(*) AS quantity, p.price, p.price * COUNT(*) AS total
FROM ticket AS t
JOIN ticketprice AS p ON t.ticket_type = p.ticket_type
WHERE t.ticket_type IN ('Adult', 'Senior')
GROUP BY t.ticket_type