我有一个数据库,其中有 id、new_name、product_id、date
1162 DC: 10us 1049902 2013-07-19
1163 DC: 12us 1049902 2013-07-19
1164 DC: 30us 1049902 2013-07-19
1165 Top 1049902 2017-07-30
1166 A:123 202302 2013-07-21
1167 A:255 2023025 2013-07-21
我需要选择日期相等的行(例如每行的日期 = 2013-07-19 和每行的 product_id =(例如)1049902)并将这些行计为 1 行
所以:
DC 1049902 = 2 (because there are two different dates that's why 2 besause it is summary (the names are differenet it doesn't matter)
A 202302 = 1
A 2023025 = 1
(查询后我只是 substr() 字符串)
等等...
我试着这样做:
select new_name, COUNT(new_name) AS n from table WHERE date<='".$today."' AND date>= '".$two_weeks_ago."' GROUP BY day(date) ORDER BY n DESC
但每一行都算我
先感谢您!