文章目录
题目
代码(7.23 首刷看解析)
UNION和JOIN的区别,JOIN是多表关联,UNION是多表数据合并。
简单来说,JOIN产生的结果如果不考虑笛卡尔积的话,数据最多会持平。
而UNION产生的结果是合并去重后的数据。 我们需要三张表分别对应"Low Salary"、“Average Salary”、“High Salary”。
# Write your MySQL query statement below
select 'High Salary' category, count(1) accounts_count from accounts a1 where income > 50000 union
select 'Average Salary' category, count(1) accounts_count from accounts a1 where income >= 20000 and income <= 50000 union
select 'Low Salary' category, count(1) accounts_count from accounts a1 where income < 20000;