一张员工表里面3W条数据,写一条最有效率的SQL语句查出

2025-02-01 01:01:08
推荐回答(2个)
回答1:

select
sum(case when age>30 and salary>9000 then 1 else 0 end) [team1],
sum(case when age>30 and salary<9000 then 1 else 0 end) [team2],
sum(case when age<30 and salary>9000 then 1 else 0 end) [team3],
sum(case when age<30 and salary<9000 then 1 else 0 end) [team4]
from 表名

回答2:

select count(*) from 员工 where age>30 and salary>9000 or age>30 and salary<9000 or age<30 and salary>9000 or age<30 and salary<9000