Rank Over Group in Mysql
in sqlCo-De with 32 comments

Rank Over Group in Mysql

in sqlCo-De with 32 comments

Q

need add increase rank num inside each type

Table

typetotal
car10
car22
truck33

Sql

select (@i := case when @pre_type=type then  @i+1 else 1 end) as rownum, t.*, (@pre_type:=type) as pre_type
from chang_moto_table t, (select @i:=0,@pre_type:='') as sidecar
group by t.total,t.type
order by t.type

Result

rownumtypetotalpre_type
1car10car
2car22car
1truck33truck

Info

Comments are closed.