i have issue. I need counting more columns where id and date. date must not be older than 7 days (1 week)
In the picture, we see the ID value as the first and the second value.
I need an SQL query to add the value 10 and 10 = 20 according to ID 344, for example
The same for the second ID. I'm tired already. Thank you
CodePudding user response:
You must have a date column to get data of last 7 days. So here is my answer after adding a 'date' column.
Answer 1. If you want sum of all the unique id's
select id, sum(object) as value, count(id) as count_of_id, from table_name WHERE date >= DATE(NOW()) - INTERVAL 7 DAY group by id
Answer 2. If you want sum of particular id
select id, sum(object) as value, count(id) as count_of_id, from table_name WHERE date >= DATE(NOW()) - INTERVAL 7 DAY and id = 344