mysql 如何按月分组查询出当前年度每个月的短信数量(数据库中这个月要是为空的话就用0条怎么显示出来) 5
以下是我的sql:(我写的这条不能显示没有数据的这个月的数量0)SELECTDATE_FORMAT(createTime,'%Y-%m')ASdate,count(*)A...
以下是我的sql:(我写的这条不能显示没有数据的这个月的数量 0)
SELECT
DATE_FORMAT(createTime, '%Y-%m') AS date,
count(*) AS count
FROM
data_shortmessage
WHERE
createTime > (
CONCAT(
DATE_FORMAT(now(), '%Y'),
'-01-01'
)
)
AND createTime <= (
CONCAT(
DATE_FORMAT(now(), '%Y'),
'-12-31'
)
)
GROUP BY
YEAR (createTime),
MONTH (createTime); 展开
SELECT
DATE_FORMAT(createTime, '%Y-%m') AS date,
count(*) AS count
FROM
data_shortmessage
WHERE
createTime > (
CONCAT(
DATE_FORMAT(now(), '%Y'),
'-01-01'
)
)
AND createTime <= (
CONCAT(
DATE_FORMAT(now(), '%Y'),
'-12-31'
)
)
GROUP BY
YEAR (createTime),
MONTH (createTime); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询