本文介绍了如何在MySQL中获取行ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取不同idfeedback的行ID

I want to get the row id of different idfeedback

SELECT  l.idfeedback_store,
    @curRow := @curRow + 1 AS row_number
FROM    feedback_store l
JOIN    (SELECT @curRow := 0) r;

结果

idfeedback_store        row_number
1                           1
1                           2
1                           3
2                           4
2                           5
2                           6
2                           7
3                           8
3                           9
3                          10
4                          11

必填结果

idfeedback_store        row_number
1                           1
1                           2
1                           3
2                           1
2                           2
2                           3
2                           4
3                           1
3                           2
3                           3
4                           1

推荐答案

尝试一下:

SELECT  l.idfeedback_store, IF(@last=(@last:=idfeedback_store), @curRow := @curRow + 1, @curRow:=1) AS row_number
FROM feedback_store l, (SELECT @curRow := 0, @last:=0) r;

这篇关于如何在MySQL中获取行ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 06:59