2

別のidfeedbackの行IDを取得したい

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
4

3 に答える 3

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;
于 2012-12-21T13:03:45.190 に答える
1

次のようなものを使用できます。

select idfeedback_store, group_row_number
from 
(
  select idfeedback_store,
    @num := if(@idfeedback_store = `idfeedback_store`, @num + 1, 1) as group_row_number,
    @idfeedback_store := `idfeedback_store` as dummy
  from feedback_store
) src

デモで SQL Fiddle を参照してください

結果:

| IDFEEDBACK_STORE | GROUP_ROW_NUMBER |
---------------------------------------
|                1 |                1 |
|                1 |                2 |
|                1 |                3 |
|                2 |                1 |
|                2 |                2 |
|                2 |                3 |
|                2 |                4 |
|                3 |                1 |
|                3 |                2 |
|                3 |                3 |
|                4 |                1 |
于 2012-12-21T12:59:08.057 に答える
0
SELECT  
  idfeedback_store,
  @curRow := CASE WHEN @curStore = idfeedback_store THEN @curRow + 1 ELSE 1 END AS row_number,
  @curStore := idfeedback_store
FROM
  feedback_store;
于 2012-12-21T12:58:46.340 に答える