我想在显示当前门票时显示每位员工的门票数量。
SELECT s.firstname, s.lastname, t.ticket_id, o.id, t.created FROM ost_ticket t
JOIN ost_staff s ON t.staff_id = s.staff_id
JOIN ost_user u ON t.user_id = u.id
JOIN ost_organization o ON u.org_id = o.id
RIGHT JOIN (
SELECT COUNT(tt.ticket_id)
FROM ost_ticket tt) a ON t.ticket_id = a.ticket_id WHERE...
我在查询中遇到错误(1054):
未知栏' a.ticket_id'在条款'。
答案 0 :(得分:1)
如果要在子查询中引用它,则需要在子查询中选择ticket_id
。
RIGHT JOIN
(
SELECT ticket_id, COUNT(ticket_id) as cnt
FROM ost_ticket
GROUP BY ticket_id
) a ON t.ticket_id = a.ticket_id