這聽起來像你需要使用這個,應用Month()
功能,無論是GVA12.FECHA_EMIS
和curDate()
:
SELECT GVA12.FECHA_EMIS, GVA12.IMPORTE, GVA14.COD_ZONA
FROM GVA12 INNER JOIN GVA14
ON GVA12.COD_CLIENT = GVA14.COD_CLIENT
WHERE Month(GVA12.FECHA_EMIS)=Month(curDate())
GROUP BY GVA12.FECHA_EMIS, GVA12.IMPORTE, GVA14.COD_ZONA
如果你想同時月份和年份來比較的話,我會用:
SELECT GVA12.FECHA_EMIS, GVA12.IMPORTE, GVA14.COD_ZONA
FROM GVA12 INNER JOIN GVA14
ON GVA12.COD_CLIENT = GVA14.COD_CLIENT
WHERE Month(GVA12.FECHA_EMIS)=Month(curDate())
AND Year(GVA12.FECHA_EMIS)=Year(curDate())
GROUP BY GVA12.FECHA_EMIS, GVA12.IMPORTE, GVA14.COD_ZONA
這將確保月份和年份相等。
如果你想有一個sum()
那麼你可以使用:
SELECT GVA14.COD_ZONA, sum(GVA12.IMPORTE)
FROM GVA12 INNER JOIN GVA14
ON GVA12.COD_CLIENT = GVA14.COD_CLIENT
WHERE Month(GVA12.FECHA_EMIS)=Month(curDate())
AND Year(GVA12.FECHA_EMIS)=Year(curDate())
GROUP BY GVA14.COD_ZONA
您創建與同一個問題一個新的職位:http://stackoverflow.com/questions/13740851/mysql-query-month-selection-錯誤/ 13740925#13740925 –
是的,但我還沒有制定出如何解決它呢! –