Everyday SQL (3)
–Common Table Expressions (not called Temporary table, many thanks to YZ to correct me, refer to http://www.sql-server-performance.com/2015/common-table-expressions-cte-developers/) with T as ( select Product_ID,max(case when MEDIA_LEG_RESULT=’T’ then 1 else 0 end) as T_leg from detail data1 where NVL(disconnect_reason,’1′) NOT IN (‘SPAM’,’DUPLICATE’) and connect_date_datetime BETWEEN to_date(‘2016-07-01 00:00:00’, ‘YYYY-MM-DD HH24:MI:SS’) and to_date(‘2016-08-01 00:00:00’, ‘YYYY-MM-DD HH24:MI:SS’) and data1.Location_id=1 group … Read more