Home > database >  Add rownum question grouping sorting
Add rownum question grouping sorting

Time:10-06

Requirements: according to the group number row_num_team group for each group of each add a sort number rownum
Implement the following:
SELECT
- rownum whether @ pre_parent_code parent_code and current, true: let @ I +=1 false: reset @ I
(
@ I:=
CASE
The WHEN @ pre_row_num_team=row_num_team
THEN @ I + 1
The ELSE 1
END
Rownum,
B. *,
-- set @ pre_parent_code equals a parent_code
(@ pre_row_num_team:=row_num_team)
The FROM
(SELECT * FROM temp_case2 WHERE ` row_num_team ` IN (' 1000 ', '10000', '10007')) b,
(SELECT
@ I:=0,
@ pre_row_num_team:=') AS a
GROUP BY
Rownum_key, row_num_team

The ORDER BY row_num_team, rownum_key

When a team can increase rownum normally, 3 groups more blind a result

CodePudding user response:

,,,,,,,,,
  • Related