我有以下查詢。MySQL查詢跳轉記錄
SELECT month(DMY) Month,
Year(DMY) Year,
Date(DMY) Date,
COD_VENDED,
@running_total := @running_total + Coalesce(TotalImport, 0) as TotalImport
from
(
SELECT Days.dmy,
g.COD_VENDED,
TotalImport
FROM Days
left join
(
select FECHA_EMIS,
COD_VENDED,
sum(IMPORTE) TotalImport
from GVA12
group by Date(FECHA_EMIS), Year(FECHA_EMIS)
) g
on date(Days.DMY) = date(g.FECHA_EMIS)
and g.COD_VENDED='EX'
and Month(g.FECHA_EMIS)=Month(curDate())
and Year(g.FECHA_EMIS)=Year(curDate())
WHERE month(Days.dmy)=Month(curDate())
) src, (SELECT @running_total := 0 AS dummy) dummy
問題是它在數據庫中跳轉記錄。
select FECHA_EMIS,
COD_VENDED,
sum(IMPORTE) TotalImport
from GVA12
group by Date(FECHA_EMIS), Year(FECHA_EMIS)
你只在Date()
和Year()
分組結果的COD_VENDED
的價值:
問題是在這個SQL Fiddle
你能否詳細說明跳樓?你什麼意思? – Taryn
那麼,如果你看看SQLFiddle上的表格,你會發現1月3日有記錄。當我運行查詢時,Jan的3返回0.這種情況很多。 –