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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。