id | userid | exerciseid | date | time | weight | distance | reps
1 | 24 | 1 | 2013-09-28 00:00:00 | 2321 | 231 | 121 | NULL
2 | 24 | 24 | 2013-09-28 00:00:00 | 2321 | 231 | 121 | NULL
3 | 24 | 1 | 2013-09-28 00:00:00 | 2321 | 231 | 121 | NULL
4 | 24 | 1 | 2000-00-00 00:00:00 | NULL | 100 | NULL | 2
5 | 24 | 1 | 2013-09-28 00:00:00 | 2321 | 231 | 121 | NULL
第 1、3 和 5 行相同。我想做一个将它们组合在一起的计数,同时还添加一个带有计数值的列。
SELECT id, userid, exerciseid, date, time, weight, distance, reps
FROM `exercises`
WHERE `userid` = 1 AND `date` < now()
所以我希望这也能返回类似的东西:
id | userid | exerciseid | date | time | weight | distance | reps | count
1 | 24 | 1 | 2013-09-28 00:00:00 | 2321 | 231 | 121 | NULL | 3
4 | 24 | 1 | 2000-00-00 00:00:00 | NULL | 100 | NULL | 2 | NULL