概述
记录一下,需要每个月的折线统计数据
sql
SELECT
yue.m AS mon,
IFNULL( a.sum, 0 ) AS sellValue
FROM
(
SELECT
1 AS m UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9 UNION ALL
SELECT
10 UNION ALL
SELECT
11 UNION ALL
SELECT
12
) yue
LEFT JOIN (
SELECT MONTH
( CREATEDATE) AS m,
sum( 金额 ) AS sum
FROM
bo_eu_riskrecord
WHERE
YEAR ( CREATEDATE ) = 具体年份
GROUP BY
MONTH ( CREATEDATE )
) a ON yue.m = a.m
ORDER BY
yue.m ASC
MySQL SUM()函数按条件求和
按条件求和
SUM(IF(fee_type=1,fee_for_balance,0))
count(if(bill_sec<=12, bill_sec, null))
MAX(IF(item_code like '%_mini', item_value, 0)) phone_mini,SUM(IF(item_code like '%_fee', item_value, ''))
SELECT MONTH
( CREATEDATE ) AS m,
sum( SXJE ) AS sxje,
sum( DKJE ) AS dkje,
sum( SQBAJE ) AS baje,
SUM(DKJE) AS sdje1,
SUM(IF(SDH = '1',DKJE,0)) AS sdje
FROM
table
数据示例:
最后
以上就是健忘口红为你收集整理的sql按月份 统计每个月的总数MySQL SUM()函数按条件求和的全部内容,希望文章能够帮你解决sql按月份 统计每个月的总数MySQL SUM()函数按条件求和所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复