我有一個MySQL查詢,它在SequelPro中正確執行,但不在PHP Mysqli中執行。顯示的消息:PHP mysqli查詢錯誤,但查詢是正確的
執行停止。 消息:執行sql語句時發生錯誤:SET @csum:= 0;選擇昆德,銷售,(@csum:= @csum + cr.sales)從cumulative_sales(和整個查詢(太長,這裏打印出來)
我試了幾次,在續集PRO,它。作品 和查詢存儲在變量$ toBeExecuted 也打印出來,以檢查其是否正確,這是
return mysqli_query($this->connectionTargetDB, $toBoExecuted);
我想那裏有與SET @csum一個問題:= 0
/編輯 整個查詢:
SET @csum := 0;
select kunde, sales, (@csum := @csum + cr.sales) as cumulative_sales
FROM (
SELECT j.kunde as kunde,
ROUND(SUM(m.ausgangsrechnungen - m.eingangsrechnungen), 2) as sales
FROM jobs_per_month m,
jobs j,
temporal_dates t
WHERE day(t._date) = 1
AND (t._date BETWEEN date_add(now(), INTERVAL -12 MONTH) and now())
AND m.monat = month(t._date)
AND m.jahr = year(t._date)
AND j.internal_jobnr = m.internal_jobnr
GROUP BY j.kunde
HAVING sales >= 10000
UNION ALL
SELECT concat(COUNT(r.sales), ' Kunde < 10k') as kunde,
ROUND(SUM(r.sales), 2) as sales
FROM (SELECT j.kunde as kunde,
ROUND(SUM(m.ausgangsrechnungen - m.eingangsrechnungen), 2) as sales
FROM jobs_per_month m,
jobs j,
temporal_dates t
WHERE day(t._date) = 1
AND (t._date BETWEEN date_add(now(), INTERVAL -12 MONTH) and now())
AND m.monat = month(t._date)
AND m.jahr = year(t._date)
AND j.internal_jobnr = m.internal_jobnr
GROUP BY j.kunde
HAVING sales < 10000 AND sales > 0) r
ORDER by sales desc) cr
引擎收錄你的SQL查詢。 – Kenyanke
我們真的需要看到整個事情,以幫助理解。 – Sand
@Sand上面添加 –