如何使用MySQL对值进行求和和分组? [英] How to sum and group values using MySQL ?

查看:400
本文介绍了如何使用MySQL对值进行求和和分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用MySQL对值进行求和和分组。现在很简单,但是我有一些奇怪的情况。



我有一个表格,允许用户每天插入吸烟量,我正在尝试要做的是每天总结数据。

任何人有任何想法如何使用php或mysql我可以总结每天吸烟数据,并按天分组?

解决方案

  SELECT 
SUM(how_many)AS per_day,
`date`
FROM
cigaretes
GROUP BY
DATE(`date`)


I was wondering how to sum and group values using MySQL. Now thats simple, however I have a bit of an odd situation.

I have a table that allows users to insert the amount of cigaretes smoked every day, what I am trying to do is sum the data for every day .

Anybody has any ideas how with php or mysql I could sum the data of cigaretes smoked per day and group it by day ?

解决方案

SELECT
    SUM(how_many) AS per_day,
    `date`
FROM
    cigaretes
GROUP BY
    DATE(`date`)

这篇关于如何使用MySQL对值进行求和和分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆