下面给出的是一个工作查询。我想用直接联合查询替换所有子查询。请建议我一个解决方案。
SELECT
id,
startTime,
endTime,
drawingTime,
result,
wpAmount,
lpAmount,
prize,
cntWinTickets,
cntLoosTickets
FROM (SELECT
i.id AS id,
i.start_time AS startTime,
i.end_time AS endTime,
i.drawing_time AS drawingTime,
i.result AS result,
SUM( t.amount ) AS wpAmount,
SUM( t.prize ) AS prize,
COUNT( t.id ) AS cntWinTickets
FROM issues i
LEFT JOIN orders o
ON o.issue_id = i.id
LEFT JOIN tickets t
ON t.order_id = o.id
AND t.has_prize = 1
GROUP BY i.id) AS A
INNER JOIN (SELECT
i.id AS lid,
SUM( t.amount ) AS lpAmount,
COUNT( t.id ) AS cntLoosTickets
FROM issues i
LEFT JOIN orders o
ON o.issue_id = i.id
LEFT JOIN tickets t
ON (t.order_id = o.id
AND (t.has_prize = 0
OR t.has_prize IS NULL))
GROUP BY i.id) AS B
ON A.id = B.lid