一、case when语句的使用
实例:查询数据,将地址编码显示为具体地点
select m.*, case m.caddr_code when 1 then '住处' when 2 then '交通地点' when 3 then '工作地点' when 4 then '运动休闲' else '其他' end as caddr_code from Vav_Radio_Sec_Action_Mem m where 1=1
二、 group by分组函数
实例:分组查询20160901至20161031日的数据总数
select dw.cdate,count(*) from vav_radio_family_mem_weight dw where dw.cdate>=to_date('20160901','yyyymmdd') and dw.cdate<=to_date('20161031','yyyymmdd') and dw.cnetworkid=4205 group by dw.cdate order by dw.cdate
三、to_date ()
实例:查询2016/11/22 2:00:00 至2016/11/23 2:00:00之间的不重复的样本编号
select distinct cfamilyid from vav_radio_sec_action_mem where cstart_time>to_date('2016/11/22','yyyy/mm/dd')+2/24 and cstart_time<to_date('2016/11/22','yyyy/mm/dd')+1+2/24 and cregion_id=4205
to_date('2016/11/22','yyyy/mm/dd')+2/24表示2016/11/22增加两小时/24小时制
to_date('2016/11/22','yyyy/mm/dd')+1+2/24 表示2016/11/22增加一天和两小时/24小时制