好久不用SQL語句了,貌似入職新公司後,又迴歸到了三年前的SQL時代,一寫一坨的SQL好吧,也當迴歸一下過去的知識。sql
下面是統計2月份某數據的計費統計code
select t.telno as 主號,VID 副號,t.area_code 地區, t.reg_time 註冊時間,t.reg_source 註冊工號,t.bill_start_date 計費時間, (case state when 0 then '0 正常' end)計費狀態 from t_unreg_log t where t.bill_start_date<to_date('20150301','yyyymmdd') and t.bill_start_date>to_date('20150201','yyyymmdd') and t.unreg_time<to_date('20150301','yyyymmdd') and t.unreg_time>to_date('20150201','yyyymmdd') and t.type='9' union select t.telno as 主號,VID 副號,t.area_code 地區, t.reg_time 註冊時間,t.reg_source 註冊工號,t.bill_start_date 計費時間, (case state when 0 then '0 正常' end)計費狀態 from t_unreg_log t where t.bill_start_date<to_date('20150301','yyyymmdd') and t.bill_start_date>to_date('20150201','yyyymmdd') and t.unreg_time>to_date('20150301','yyyymmdd') union select t.telno as 主號,VID 副號,t.area_code 地區, t.reg_time 註冊時間,t.reg_source 註冊工號,t.bill_start_date 計費時間, (case state when 0 then '0 正常' end)計費狀態 from t_unreg_log t where t.bill_start_date is not null and t.bill_start_date<to_date('20150201','yyyymmdd') and t.unreg_time<to_date('20150301','yyyymmdd') and t.unreg_time>to_date('20150201','yyyymmdd') and t.type='9' union select t.telno as 主號,VID 副號,t.area_code 地區, t.reg_time 註冊時間,t.reg_source 註冊工號,t.bill_start_date 計費時間, (case state when 0 then '0 正常' end)計費狀態 from t_online_info t where t.bill_start_date is not null and t.bill_start_date<to_date('20150301','yyyymmdd'))
寫完以後發現這麼多的冗餘代碼。blog