欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql自动生成排序列复杂sql的方法

程序员文章站 2023-11-03 09:05:52
使用sql语句原功能 select@rownum := @rownum+1as rownum, table1.* from(select @rownum:=0) r, table1; 生成语句 se...

使用sql语句原功能

select@rownum := @rownum+1as rownum,

table1.*

from(select @rownum:=0) r,

table1;

生成语句

select @rownum:=@rownum+1 as rank,t.* from (select @rownum:=0+"+num+") r,

(select distinc p.name,p.type,p.salaryno,h.day_profit_rate as profit,h.month_profit_rate,h.quarter_profit_rate,h.total_profit_rate,

h.competition_total_asset,h.account_total_asset,h.competition_total_asset/h.account_total_asset as ratio,

h.competition_month_average_asset,h.competition_quarter_average_asset,h.competition_total_average_asset,h.sj

from stock_competition_player p join stock_competition_user_info_history h

on p.salaryno = h.salaryno order by h.sj desc, h.day_profit_rate desc )t