考虑下表(“推文”):
+---------+------------+----------+
| user_id | _date | tweet_id |
+---------+------------+----------+
| 1 | 2011-03-17 | 12 |
| 1 | 2011-03-17 | 16 |
| 1 | 2011-01-18 | 17 |
| 2 | 2011-03-18 | 23 |
| 2 | 2011-01-17 | 29 |
| 2 | 2011-03-17 | 32 |
| 2 | 2011-01-17 | 33 |
| 2 | 2011-03-18 | 34 |
| 2 | 2011-01-19 | 45 |
| 2 | 2011-03-19 | 48 |
| 3 | 2011-01-19 | 50 |
| 3 | 2011-03-19 | 51 |
| 3 | 2011-01-19 | 52 |
| 3 | 2011-01-20 | 53 |
+---------+------------+----------+
我想要以下输出: 每个用户按日期排序的推文:
user_id _date cnt
------------------------
1 2011-03-17 2
1 2011-03-18 1
2 2011-03-17 3
2 2011-03-18 2
2 2011-03-19 2
3 2011-03-19 3
3 2011-03-20 1
我不明白为什么,但这不起作用:
SELECT user_id, _date, COUNT(tweet_id) AS cnt FROM tweets
GROUP BY nyse_date ORDER BY sp100_id ASC
有人可以向我解释为什么吗?