忙活大半天,终于找出了自己写的SQL语句中的问题。
错误前:
SELECT CAST(MONTH(stat_date) AS CHAR) as stat_date ,CAST(COUNT(month(stat_date)) AS CHAR)AS prodcode FROM tb_ac_syzworder
WHERE (SELECT MONTH(stat_date))>(select MONTH(NOW())-4) AND (select MONTH(stat_date))<=(select MONTH(NOW()))
GROUP BY stat_date
经过老司机的指点,找出了错误原因,其实很简单,之前学sql server时记得老师曾经强调过的。
SELECT CAST(MONTH(stat_date) AS CHAR) as stat_date ,CAST(COUNT(month(stat_date)) AS CHAR)AS prodcode FROM tb_ac_syzworder
WHERE (SELECT MONTH(stat_date))>(select MONTH(NOW())-4) AND (select MONTH(stat_date))<=(select MONTH(NOW()))
GROUP BY CAST(MONTH(stat_date) AS CHAR)
GROUP BY的条件要和SELECT中的一致,不然就会报错的!!!
长点心吧!!!