码迷,mamicode.com
首页 > 数据库 > 详细

sql partition by 的使用

时间:2014-08-06 18:49:01      阅读:1067      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   使用   io   2014   art   

select
        a.bs_sn,
        a.bs_bd_no,
        a.bs_bk_code,
        a.bs_kind_no,
        a.bs_flag,
        b.det_flag,
        c.bp_in_no,
        c.bp_name,
        c.bp_sex,
        c.bp_age,
        c.bp_age_unit,
        c.bp_dept,
        c.bp_bed_no,
        d.inf_date,
        d.inf_type,
        e.sta_date,
        e.sta_user    
              from bd_stock as a 
                left join (select row_number() over (partition by det_bs_sn order by det_flag DESC) as rownum,det_bs_sn,det_id,det_flag from dbo.bd_match_detail where det_flag!=-1) as b on a.bs_sn=b.det_bs_sn and b.rownum=1
                left join bd_patients as c on b.det_id=c.bp_id
                left join (select row_number() over (partition by inf_bp_id,inf_bd_sn order by inf_date DESC) as rownum,inf_bp_id,inf_bd_sn,inf_type,inf_date from bd_infusion where inf_type = 1) as d on b.det_id = d.inf_bp_id and b.det_bs_sn=d.inf_bd_sn and d.rownum=1
                left join (select row_number() over (partition by sta_code,sta_sta_code order by sta_date DESC) as rownum,sta_code,sta_sta_code,sta_user,sta_date from dbo.bd_status where sta_sta_code=10600) as e on a.bs_bd_no=e.sta_code         
            where b.det_flag=6  and d.inf_date>=2013-12-02 and d.inf_date<=2014-12-02

 

sql partition by 的使用,布布扣,bubuko.com

sql partition by 的使用

标签:des   style   blog   color   使用   io   2014   art   

原文地址:http://www.cnblogs.com/zhangcybb/p/3895176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!