关于 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 [b][color=red]s.period between d.start_date and d.end_date[/color][/b]
and k.capital_account = '10020661'
group by s.cust_id, v.branch_abbrev,k.cust_name, k.capital_account, nvl(l.name,'')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值