Everyday SQL (1)

最基本的常用sql code

今天用了一天R和SQL,SQL是在Data Ware House (DW) 跑的,具体的流程十几分钟一学就会,主要是要会写SQL code. 我是自学的,贴一段工作中用的最基本的,初学者可以先从最基本的和理解这段code开始,学会最常用的where 和 left join。

select distinct tabled.comm_id, o1.component_id as sic1, o2.component_id as sic2
from contact_detail tabled
left join (select comm_id,component_id  from components where type_code=111) o1
on tabled.comm_id=o1.comm_id
left join (select comm_id,component_id  from components where type_code=222) o2
on tabled.comm_id=o2.comm_id
where disconnect_date between  to_date(‘2016-08-16 00:00:00’, ‘YYYY-MM-DD HH24:MI:SS’) and to_date(‘2016-08-31 00:00:00’, ‘YYYY-MM-DD HH24:MI:SS’)

Be the first to comment

Leave a Reply

Your email address will not be published.


*