我正在尝试为MySQL更新组中的单个行构造一条SQL语句。以记录下面我需要更新值isPrimary标志,使每个用户的最早记录设置为1更新组中最早的一行
ID | UserID | Inserted | IsPrimary
----------|-------------|-------------|----------
000f83 | 79b8c3 | 2012-03-14 | 0
001401 | 79b8c3 | 2012-03-15 | 0
002e7d | 4652a2 | 2012-02-22 | 0
003ca6 | 4652a2 | 2012-02-13 | 0
所以上述记录将最终成为:
ID | UserID | Inserted | IsPrimary
----------|-------------|-------------|----------
000f83 | 79b8c3 | 2012-03-14 | 1
001401 | 79b8c3 | 2012-03-15 | 0
002e7d | 4652a2 | 2012-02-22 | 0
003ca6 | 4652a2 | 2012-02-13 | 1
组中的多行可能在'inserted'中有相同的日期吗? – zerkms 2012-04-12 04:49:16
不,我把它缩写为问题的日期,但实际上该领域也有时间。 – sipwiz 2012-04-12 05:01:11