我有这样的表:
_id| letter| extra
1 | A | some
2 | A | another
3 | A | information
4 | B | NULL
5 | B | 98090
当LETTER改变时,我需要区分第一行:
_id| letter| extra | mediator
1 | A | some | 1
2 | A | another |
3 | A | information |
4 | B | NULL | 1
5 | B | 98090 |
或......
_id| letter| extra | count
1 | A | some | 1
2 | A | another | 2
3 | A | information | 3
4 | B | NULL | 1
5 | B | 98090 | 2
(在这种情况下,我知道我需要数= 1)
答案 0 :(得分:1)
以下查询搜索这些ID(假设“first”表示“最小_id
值”):
SELECT MIN(_id)
FROM MyTable
GROUP BY letter
以下语句将设置mediator
列:
UPDATE MyTable
SET mediator = 1
WHERE _id IN (SELECT MIN(_id)
FROM MyTable
GROUP BY letter)