SQlite SELECT语句别名

时间:2017-10-13 13:01:51

标签: sql sqlite

SQlite中是否有某种WITH表达式?

例如,我试图做(不工作)

SELECT s.name AS 'service',
(SELECT value FROM payments WHERE (serviceId = s.id) AND (managerId = $managerId)) AS 'payment',
COUNT(s.name) AS 'amount',
('payment' * 'amount') AS summary         //that is the point I want to optimise
FROM tickets t
JOIN services_to_tickets st ON t.id = st.ticketId
JOIN services s ON st.serviceId = s.id
JOIN medics m ON t.medicId = m.id
JOIN managers mg ON mg.id = m.managerId
WHERE mg.id = $managerId
GROUP BY service

0 个答案:

没有答案