您的位置:首页 > 数据库

sql中left join(left outer join)、inner join的使用,right join(right outer join)的用法和left join的相反就可以了。

2010-11-19 15:22 633 查看
下面是一段137行的sql语句,如果把这个看懂的话,我想对left join,inner join,就基本上了解的没问题了吧(只是个人意见)

下面是一段代码:

select num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,area.areaCode areaCode,area.areaName areaName, num11

from
(select area_code areaCode,area_name areaName, fa.grade_path grade,fa.id
from fk_area fa
where fa.father_id = (select id from fk_area where area_code = 330203008000) and fa.is_deleted = 0) area

left join
(select mc.zfjcs num1, mc.area_id areaId
from jd_mbkh_config mc
where mc.is_deleted = 0
and mc.year = '2010') map1 on map1.areaId = area.id

left join
(select count(sc.id) num2,info.fouth_area as areaCode
from jd_safe_check sc
inner join jd_company c on c.id = sc.par_id2
inner join fk_user_info info on info.id = sc.user_id
where sc.is_deleted = 0
and sc.father_id is null
and c.is_deleted=0
and c.is_recycle=0
and sc.check_Time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and sc.check_Time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss')
group by info.fouth_area ) map2 on map2.areaCode = area.areaCode

left join
(select count(sc2.id) num3,info.fouth_area as areaCode from jd_safe_check sc2 inner join jd_company c on c.id = sc2.par_id2
inner join fk_user_info info on info.id = sc2.user_id
where sc2.is_deleted = 0
and sc2.father_id is not null
and c.is_deleted=0
and c.is_recycle=0
and sc2.check_Time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and sc2.check_Time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss')
group by info.fouth_area ) map3 on map3.areaCode = area.areaCode

left join
(select count(sc3.id) num4,info.fouth_area as areaCode from jd_safe_check sc3
inner join jd_company c on c.id = sc3.par_id2
inner join fk_user_info info on info.id = sc3.user_id
where not exists
(select 1 from jd_hidden_trouble ht where sc3.id = ht.par_id2)
and sc3.is_deleted = 0
and sc3.father_id is null
and c.is_deleted=0
and c.is_recycle=0
and sc3.check_Time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and sc3.check_Time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss')
group by info.fouth_area ) map4 on map4.areaCode = area.areaCode

left join
(select count(ht.id) num5,info.fouth_area as areaCode from jd_hidden_trouble ht
inner join fk_user_info info on info.id = ht.user_id
inner join jd_safe_check che on che.id= ht.par_id2
inner join jd_company c on c.id = ht.par_id
where ht.is_deleted = 0
and ht.government_time is not null
and (ht.trouble_type='trouble_type_common'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map5 on map5.areaCode = area.areaCode

left join
(select count(ht2.id) num6,info.fouth_area as areaCode from jd_hidden_trouble ht2
inner join fk_user_info info on info.id = ht2.user_id
inner join jd_safe_check che on che.id= ht2.par_id2
inner join jd_company c on c.id = ht2.par_id
where ht2.is_deleted = 0
and ht2.government_time is null
and (ht2.trouble_type='trouble_type_common'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map6 on map6.areaCode = area.areaCode

left join
(select count(ht.id) num7,info.fouth_area as areaCode from jd_hidden_trouble ht
inner join fk_user_info info on info.id = ht.user_id
inner join jd_safe_check che on che.id= ht.par_id2
inner join jd_company c on c.id = ht.par_id
where ht.is_deleted = 0
and ht.government_time is not null
and (ht.trouble_type='trouble_type_great'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map7 on map7.areaCode = area.areaCode

left join
(select count(ht2.id) num8,info.fouth_area as areaCode from jd_hidden_trouble ht2
inner join fk_user_info info on info.id = ht2.user_id
inner join jd_safe_check che on che.id= ht2.par_id2
inner join jd_company c on c.id = ht2.par_id
where ht2.is_deleted = 0
and ht2.government_time is null
and (ht2.trouble_type='trouble_type_great'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map8 on map8.areaCode = area.areaCode

left join
(select count(ht.id) num9,info.fouth_area as areaCode from jd_hidden_trouble ht
inner join fk_user_info info on info.id = ht.user_id
inner join jd_safe_check che on che.id= ht.par_id2
inner join jd_company c on c.id = ht.par_id
where ht.is_deleted = 0
and ht.government_time is not null
and (ht.trouble_type='trouble_type_other'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map9 on map9.areaCode = area.areaCode

left join
(select count(ht2.id) num10,info.fouth_area as areaCode from jd_hidden_trouble ht2
inner join fk_user_info info on info.id = ht2.user_id
inner join jd_safe_check che on che.id= ht2.par_id2
inner join jd_company c on c.id = ht2.par_id
where ht2.is_deleted = 0
and ht2.government_time is null
and (ht2.trouble_type='trouble_type_other'
and c.is_deleted=0 and c.is_recycle=0
and che.check_time >= to_date('2010-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and che.check_time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss') )
group by info.fouth_area ) map10 on map10.areaCode = area.areaCode

left join
(select count(c.id) num11,fouth_area as areaCode from jd_company c
where c.is_deleted = 0
and c.IS_recycle = 0
and c.create_Time >= to_date('1949-01-01 00:00:00','yyyy-MM-dd hh24:mi:ss')
and c.create_Time <= to_date('2010-12-31 23:59:59','yyyy-MM-dd hh24:mi:ss')
group by c.fouth_area ) map11 on map11.areaCode = area.areaCode
order by grade
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐