select l.jobid, l.cityid, (select count(*) + 1 from tbljob_city where jobid = l.jobid and cityid < l.cityid) as ordinal_number from tbljob_city l where l.jobid = 7 or l.jobid = 30 order by l.jobid, l.cityid;
+-------+--------+----------------+
| jobid | cityid | ordinal_number |
+-------+--------+----------------+
| 7 | 24 | 1 |
| 7 | 29 | 2 |
| 30 | 24 | 1 |
| 30 | 29 | 2 |
+-------+--------+----------------+
Không có nhận xét nào:
Đăng nhận xét