Home  >  Article  >  Backend Development  >  mysql数据问题 grounp by 行不行?

mysql数据问题 grounp by 行不行?

WBOY
WBOYOriginal
2016-06-23 13:40:081234browse


表table,字段如图
我想取得d_consutotal的总和,但是条件是要FROM_UNIXTIME(d_inputdate,'%Y-%m')='2015-02' AND d_adaccount='1',并且按条件来,相同的d_consutotal只取一个(要的结果就是3055.52+1111.11.........),现在这所有的d_inputdate转换后都是"2015-02'"了。
请问这语句该怎么写呢?


回复讨论(解决方案)

求和用 sum 函数
对 d_consutotal 求和,写作 sum(d_consutotal)
相同的d_consutotal只取一个,则写作 sum(DISTINCT d_consutotal)

既然你有 FROM_UNIXTIME(d_inputdate,'%Y-%m')='2015-02' AND d_adaccount='1' 的条件约束,自然只会得到 2015 年 2 月的数据结果

求和用 sum 函数
对 d_consutotal 求和,写作 sum(d_consutotal)
相同的d_consutotal只取一个,则写作 sum(DISTINCT d_consutotal)

既然你有 FROM_UNIXTIME(d_inputdate,'%Y-%m')='2015-02' AND d_adaccount='1' 的条件约束,自然只会得到 2015 年 2 月的数据结果


祖宁兄真是博闻强识啊,已经搞定了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn