0
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
4

2 に答える 2

2

これを試して

SELECT id, userid, exerciseid, date, time, weight, distance, reps,
       count(*) as count
FROM `exercises`
WHERE userid = 1 AND date < now()
GROUP BY id, userid, exerciseid, date, time, weight, distance, reps    
于 2013-10-03T16:09:17.690 に答える
0

これを試して :

SELECT Count(*) As CountM, id, userid, exerciseid, date, time, weight, distance, reps    
FROM `exercises`
WHERE `userid` = 1 AND `date` < now()
Group by id, userid, exerciseid, date, time, weight, distance, reps  
于 2013-10-03T16:09:10.113 に答える