0

我有这样的表:

_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

(在这种情况下,我知道我需要 count = 1)

4

1 回答 1

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)
于 2013-06-07T13:30:27.490 回答