我在每个用户ID /用户名上都有多个条目。因为所有都有不同的id (auto inc)
我想过滤结果添加额外的编号,以便在我们使用以下查询时
select * from table_name where uid='4'
然后获取的结果就像
uname work number
4 paint 1
4 cook 2
这里的数字列是我想要相应地安排取得的结果。
答案 0 :(得分:3)
这是使用变量在MySQL中执行此操作的技巧:
select t.*, @rn := @rn + 1 as number
from table_name t cross join (select @rn := 0) const
where uid='4'