Quantcast
Viewing all articles
Browse latest Browse all 4

T-SQL Question

cREATE TABLE mytable(
   order_dt    DATE  NOT NULL  
  ,source_type VARCHAR(3) NOT NULL
  ,co2         INT 
);
INSERT INTO mytable(order_dt,source_type,co2) VALUES
 ('12-31-2018','abc',50)
,('12-31-2018','cde',30)
,('12-31-2018','xyz',52)
,('12-30-2018','abc',45)
,('12-30-2018','cde',NULL)
,('12-29-2018','xyz',NULL);


select source_type from mytable t1
 where t1.co2 is not null and t1.order_dt = '12-31-2018' 
and exists(
select source_type from mytable t2
 where  t2.source_type=t1.source_type 
 and (t2.co2 is NULL and (t2.order_dt = '12-30-2018' or t2.order_dt = '12-29-2018')))

 
 drop table mytable


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>