首頁  >  文章  >  資料庫  >  sqlserver中排序取数据的问题

sqlserver中排序取数据的问题

WBOY
WBOY原創
2016-06-07 16:17:531399瀏覽

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 的数据,具体情况可以根据实际需求修改

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn