我想显示SUM()的结果,其中结果不是0(零)
MySQL Table Name:
memberlist
Columns:
m_username
2021_03_24
2021_03_17
2021_03_10
2021_03_03
2021_02_24
2021_02_17
MySQL Query:
SELECT *, SUM( IFNULL(2021_03_24, 0) + IFNULL(2021_03_17, 0) + IFNULL(2021_03_10, 0) + IFNULL(2021_03_03, 0) + IFNULL(2021_02_24, 0) + IFNULL(2021_02_17, 0) ) AS TOTAL_CONTRIBUTION FROM memberlist GROUP BY m_username ORDER BY TOTAL_CONTRIBUTION DESC`
以上MYSQL查询有问题:
It shows results where `TOTAL_CONTRIBUTION` = 0
如何修改MySQL查询,使结果排除TOTAL_CONTRIBUTION
=0的任何数据?
HAVING子句
SELECT *,
SUM(
IFNULL(2021_03_24, 0)
+ IFNULL(2021_03_17, 0)
+ IFNULL(2021_03_10, 0)
+ IFNULL(2021_03_03, 0)
+ IFNULL(2021_02_24, 0)
+ IFNULL(2021_02_17, 0)
) AS TOTAL_CONTRIBUTION
FROM memberlist
GROUP BY m_username
HAVING TOTAL_CONTRIBUTION!=0
ORDER BY TOTAL_CONTRIBUTION
DESC;
网友评论