I have the following table in a database. I want to be able to get the sum of the value colum but only based on the date. so if today was january 1st i only want the sum for every value that has jan 1st as the date. I am using the following:
SELECT SUM(value) AS value_today FROM table_value GROUP BY date ORDER BY date DESC
Only problem is that it only returns the sum for december 22 and nothing new entered into the database.
+-------+---------+------------+
| ID | value | date |
+-------+---------+------------+
| 1 | 3 | 2011-12-22 |
| 2 | 2 | 2011-12-22 |
| 3 | 4 | 2011-12-22 |
| 4 | 2 | 2012-01-01 |
+-------+---------+------------+
SELECT SUM(value) AS value_today FROM table_value WHERE date = CURDATE()
Something like this?
If it is not, maybe you can rephrase your question.
SELECT SUM(value) AS value_today FROM table_value WHERE date = DATE(NOW())
这样,您只能检索今天的数据总和。
SELECT sum(value), date FROM table WHERE date = 2012-01-01 ORDER BY date DESC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.