我想加入2個不同的查詢。每個查詢單獨工作,但在加入時不工作。問題MySQL聯合查詢
SELECT *
FROM (
SELECT i.id AS wid, i.start_time, i.end_time, i.drawing_time, i.result, SUM(t.amount) AS wpAmount, SUM(t.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
JOIN
SELECT *
FROM (
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 !=1
GROUP BY i.id
) AS B ON A.wid = B.lid
內部查詢工作正常,但加入後無法正常工作。
以下是錯誤消息:
MySQL表示:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM (
SELECT i.id as lid, SUM(t.amount) AS lpAmount , COUNT(t.id)' at line 12
不工作怎麼樣? – sashkello 2013-04-26 07:34:53
刪除第二個SELECT * FROM,這是加入後 - 你不需要它... – sashkello 2013-04-26 07:35:30
@sashkello:檢查更新的問題PLZ。 – 2013-04-26 07:37:59