自学内容网 自学内容网

MySQL | union all 和union(去重和不去重)

题1:

现在运营想要分别查看学校为山东大学或者性别为男性的用户的device_id、gender、age和gpa数据,请取出相应结果,结果不去重

示例:user_profile

根据示例,你的查询应返回以下结果:

UNION(并)

使用 UNION可以实现将多个查询结果集合并为一个结果集。

union [all]

all表示在结果集中不去除重复的记录。如果没有指定all,则去除合并后结果集中的重复记录。

select device_id,gender,age,gpa
from user_profile
where university='山东大学' 
union all
select device_id,gender,age,gpa
from user_profile
where gender='male'

原文地址:https://blog.csdn.net/jingling555/article/details/142550116

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!