where子句TSQL中的缺省值

时间:2017-11-16 20:13:30

标签: sql-server

我在很新,并希望有人可以帮助我。我希望的是如何获得尚未收到的地点或为该集合购买物品的一些建议。除了那些。我想在值字段中加上一个通用数字或null。

select 
    location, count(*) as [value]
from 
    item
where 
    creation_date >= datediff (dd, '1 Jan 1970', '1 January 2017')
    and creation_date <= datediff (dd, '1 Jan 1970', '31 December 2017')
    and collection in ('ab', 'blu', 'cd', 'dvd', 'eab', 'ecd', 'edvd', 'frdvd', 'jab', 'jcd', 'jdvd', 'mus', 'vg', 'yaab', 'yacd', 'yadvd')
    and location in ('aal', 'aali', 'aami')
    and item# not in (select item# from po_line_item where item# is not null)
    ---insert horrible stuff here to get total counts by location
    or (item# in (select item# 
                  from po_line_item 
                  where receive_date >= datediff (dd, '1 Jan 1970', '1 January 2017')
                    and receive_date <= datediff (dd, '1 Jan 1970', '31 December 2017')
                 )
        and collection in ('ab','blu','cd','dvd','eab','ecd','edvd','frdvd','jab','jcd','jdvd','mus','vg','yaab','yacd','yadvd')
        and location IN ('aal', 'aali', 'aami')
       )
 group by 
     location
 order by 
     location

0 个答案:

没有答案