题解 25 | #查找山东大学或者性别为男生的信息#

【场景】:查找A或B

【分类】:行合并不去重

分析思路

难点:

1.先输出学校为山东大学的用户,后输出性别男的用户

2.如何不去重,使用union all 而不是where or

(
select 查询结果 [试卷ID;性别;年龄;gpa]
from 从哪张表中查询数据[用户信息表]
where 查询条件 [山东大学]
)
union all
(
select 查询结果 [试卷ID;性别;年龄;gpa]
from 从哪张表中查询数据[用户信息表]
where 查询条件 [男性]
)

求解代码

方法一:

union 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'
)
全部评论

相关推荐

07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-24 13:32
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务