Oracle表的常用查询实验(八)

1.问题描述:

有一store_fee表,表中有四个字段(会员卡编号、办卡店编号、消费情况、消费店编号)

Oracle表的常用查询实验(八)

现要统计各店的办卡总计和消费总计

2.需求分析:

在A店办卡的会员,可能会在其他店里进行消费

3.解答过程:

(1)求各店的办卡统计情况

Oracle表的常用查询实验(八)

(2)求各店的消费统计情况

Oracle表的常用查询实验(八)

(3)将以上2个结果集联合起来

Oracle表的常用查询实验(八)

4.SQL代码:

select t1.dept_no, t1.办卡统计, t2.消费统计
from (select dept_no, count(*) 办卡统计 from store_fee group by dept_no) t1
left join (select deptno_no2, sum(fee) 消费统计
from store_fee
group by deptno_no2) t2
on t1.dept_no = t2.deptno_no2
order by dept_no;

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2022-01-06
  • 2022-02-12
  • 2021-12-31
  • 2021-07-23
  • 2021-08-28
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2022-02-26
  • 2022-02-08
  • 2021-06-15
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案