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 的數據,具體情況可以根據實際需求修改