php - Mysql return the row position with sorting -


the ff table:

+-----------------------------+ + value| name   |asort        + +-----------------------------+ +  111 | alpha  |a            + +  161 | beta   |b            + +  092 | delta  |c            + +  141 | beta   |a            + +  113 | beta   |e            + +  092 | delta  |f            + +  ...                        + +  ... | more items           + +-----------------------------+     +-----------------------------+ + value| name |asort          + +-----------------------------+ +  141 | beta |a              + +  161 | beta |b              + +  113 | beta |c              + +  ...                        + +  ... | more items(beta)     + +-----------------------------+ 

i want return of "3" "113" row position group name beta , sort asc asort

you need use variable calculate rank (row-number-in-mysql) because mysql doesnt have row_number.

sql fiddle demo

select ff.*,         @rownum := @rownum + 1 rank   ff,         (select @rownum := 0) r name = 'beta'   order asort 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -