Palpitate123 2021-06-20 22:54 采纳率: 100%
浏览 44
已结题

关系数据库SQL中,union all语句具体用法?

 在关系数据库(如MySQL)中,有公司员工收入表t_income,包含字段:dept 部门、name员工姓名、income收入。现要统计每个员工的总收入、每个部门的总收入和全公司的总收入,可以用以下哪个SQL语句实现?(正确答案个数:2个)

A. select dept,name,sum(income) from t_income group by dept,name with cube;
B. select dept,name,sum(income) from t_income group by dept,name with rollup;
c. select dept,name,sum(income) from t_income group by dept,NAME union all select dept,",sum(income) from t_income group by dept union all select ", ",sum(income) from t_income;
D.select dept,name,sum(income) from t_income group by dept,NAME union all select dept,",sum(income) from t_income group by dept union all select ",name,sum(income) from t_income group by name union all select ",",sum(income) from t_income;

正确答案为B\C项

请帮忙解释一下为什么C项正确

  • 写回答

2条回答 默认 最新

  • 关注

    B应该是很容易理解的

    C主要是要了解union all是什么意思,union其实是把三条独立的SQL语句查询,然后把结果显示在一起。

    这就是union的作用,只要结构相同就可以使用union实现独立SQL语句的结果显示在一起。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月1日
  • 已采纳回答 8月24日

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?