如何利用SQL语句将多个工作表中具有相同属性的数据汇总起来
答案:1 悬赏:20
解决时间 2021-01-31 10:41
- 提问者网友:醉归
- 2021-01-30 21:27
如何利用SQL语句将多个工作表中具有相同属性的数据汇总起来
最佳答案
- 二级知识专家网友:颜值超标
- 2021-01-30 22:54
将多个表中的数据汇总最常用的办法是使用union all,具体的要视表结构、“相同属性”的具体定义、汇总方式等因素而定,可能还要用到连接、筛选、子查询、分组等手段,当然聚合函数sum是少不了的。
下面例子实现将t1,t2,t3中的各个产品汇总起来,显示每种产品的总量:
select t.product ,sum(t.qty) from
(select product,qty from t1
union all
select product,qty from t2
union all
select product,qty from t3) t
group by t.product;
下面例子实现将t1,t2,t3中的各个产品汇总起来,显示每种产品的总量:
select t.product ,sum(t.qty) from
(select product,qty from t1
union all
select product,qty from t2
union all
select product,qty from t3) t
group by t.product;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯