【场景】:查找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'
)