关于 join 的一个查询问题

下面的查询中,红色部分是查询结果正确的关键。
至今没想明白为什么要这么写,记录一下,欢迎高人指点。

【数据】
select t.id,t.cust_id,t.period,t.last_point,t.period_point,t.present_point,t.sum_point
from integral.tb_cust_integral_sum t where t.cust_id='2536377'

1 600976 2536377 200807 0 2067.3044775 0 2067.3044775
2 541688 2536377 200802 0 2067.3044775 0 2067.3044775
3 571332 2536377 200803 0 2067.3044775 10 2037.3044775


【想不明白的查询】
select s.cust_id as id,
                 v.branch_abbrev as 部门名称,
                 k.cust_name as 客户姓名,
                 k.capital_account as 资金帐号,
                 nvl(l.name,'') as 客户等级,
                 sum(s.period_point) as 总积分,
                 sum(s.present_point) as 总回馈,
                 sum( case when  '20080701'  between d.start_date and d.end_date then s.period_point else 0 end) as 当期积分,
                 sum( case when  '20080701'  between d.start_date and d.end_date then s.present_point else 0 end) as 当期回馈,
                 sum( case when  '20080701'  between d.start_date and d.end_date then s.sum_point else 0 end) as 当期剩余积分
                 from integral.tb_cust_integral_sum s
                 inner join kmms.tb_trade_cust k on s.cust_id=k.cust_id
                 inner join sysmanage.vw_branch_sub_company v on k.branchid = v.branch_id
                 inner join integral.tb_dept_integral d on v.sub_id = d.dept_id
                 left join integral.tb_cust_level c on s.cust_id=c.cust_id
                 left join integral.tb_integral_level l on c.level_id=l.in_level
                where s.period between d.start_date and d.end_date
                 and k.capital_account = '10020661'
               group by s.cust_id, v.branch_abbrev,k.cust_name, k.capital_account, nvl(l.name,'')

你可能感兴趣的:(C++,c,C#)