How to sum and group values using MySQL ?

2019-10-03 04:20发布

问题:

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 ?

回答1:

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