SQL Server:排除具有空值的行

时间:2019-05-14 08:55:06

标签: sql sql-server

以下SQL查询每周汇总数据,即to_char(sysdate, 'WW')。数据仅在星期六更新。因此,当没有数据显示除聚合之外的其他文本列时,将使用联接。

结果:https://ibb.co/6Wx364g

 select 
       mbz.mill,
       sm.sugar_mill_order,
       fhi.hczname as ZONE,
       sd.name as STATION,
       di.descrip,
       di.unit,
       wd.record_year,
       to_char(sysdate, 'YYYY') as year,
       to_char(sysdate,'WW') as week,
       sd.station_num,
       round(nvl(wd.dvalue,null), 1) as Station_Reading,
       round(avg(nvl(wd.dvalue,null))
             over(partition by mbz.mill, fhi.hczname, wd.dcode, wd.record_year),
             1) as Zone_Average,
       round(avg(nvl(wd.dvalue,null)) over(partition by mbz.mill), 1) as Mill_Average,
       --round(avg(nvl(wd.dvalue,0))over(partition by mbz.mill),2) AS Average_For_Report,
       /*(case when wd.dvalue is not null
             then round(avg(nvl(wd.dvalue,0))over (partition by mbz.mill order by sm.sugar_mill_order, wd.dvalue asc),2) 
        end) as Average_for_report,*/
       round(avg(msa.dvalue) over(partition by mbz.mill),1) AS LTM
   from mill_by_zone mbz
join sugar_mills sm
    on sm.sugar_mill_name = mbz.mill
join zone_by_station zbs
    on zbs.zone = mbz.zone
join fca_hcz_info fhi
    on fhi.hcz = zbs.zone
inner join station_details sd
    on sd.station_num = zbs.station
left join 
     weekly_data wd
                 on wd.station_num = sd.station_num and
                 wd.record_year = 2019 and
                 wd.dcode = 1 and
                 wd.record_week = to_char(sysdate,'WW') and wd.dcode = 1 
left join data_items di
    on (wd.dcode = di.code_num ) 
left join msa_ltm_data msa
    on( msa.record_mth = to_char(wd.last_update_date,'MM') and msa.dcode = wd.dcode and msa.mill_num = sm.sugar_mill_number ) 
order by sm.sugar_mill_order, wd.dvalue

当图片中有数据时,如何排除空白。谢谢

0 个答案:

没有答案