sqlserver中关于排序取数据的问题 select * from (select *,row_number() over (partition by wok.flag_3 order by wok.createtime desc) rownum from (select workh.corp_code,workh.corp_name,workh.begin_date, workh.createtime, workh.flag_1,workh.fla
sqlserver中关于排序取数据的问题
select * from (select *,row_number() over (partition by wok.flag_3 order by wok.createtime desc)
rownum from (select workh.corp_code,workh.corp_name,workh.begin_date, workh.createtime,
workh.flag_1,workh.flag_2,workb.main_id,workb.production_quantity,workb.spare_capacity,
workb.equipment_code,workb.flag_3 from imp_workorderh workh right join imp_workorderb workb
on workb.main_id = workh.id where workh.teachingplanid = '0000aa10000000016f6u') wok ) h where h.rownum = 1)
此查询是按时间倒序排列后 然后取出rownum为1 的数据,具体情况可以根据实际需求修改
,