1
故事:我有一個單一的MySQL表,我得到3個值(總和)與下面的查詢。查詢正在工作。但它需要7.624秒,對我來說太長了。試圖找到更好的SQL查詢。你可以幫我嗎?Mysql - 3個獨立的總數從1表 - 工程 - 尋找更好的查詢
SELECT
DATE(a.tarih),
(
SELECT
SUM(s.stoplam)
FROM
siparis s
WHERE
s.durum_id IN (4, 26, 27, 28, 29)
AND DATE(s.tarih) = DATE(a.tarih)
) AS iptal,
(
SELECT
SUM(c.stoplam)
FROM
siparis c
WHERE
c.durum_id NOT IN (4, 26, 27, 28, 29)
AND DATE(c.tarih) = DATE(a.tarih)
) AS Ciro,
(
SELECT
SUM(d.stoplam)
FROM
siparis d
WHERE
d.durum_id NOT IN (4, 26, 27, 28, 29)
AND DATE(d.tarih) = DATE_ADD(
DATE(a.tarih),
INTERVAL - 30 DAY
)
) AS GCiro
FROM
siparis a
WHERE
DATE(a.tarih) > DATE_ADD(CURDATE(), INTERVAL - 30 DAY)
GROUP BY
DATE(a.tarih)
是您的一個別名是孤兒還是我瞎了? – Mihai 2014-10-31 13:48:57
@Mhai它似乎並不是完整的查詢 – 2014-10-31 14:08:20
對不起。現在應該是一個完整的查詢。編輯。 – yavuzkirez 2014-10-31 14:10:22