不错的sql题一道

来源:百度知道 编辑:UC知道 时间:2024/09/20 21:40:43
已知关系数据库的模型如下:staff(staff_id,name,salary,birthday),写sql查找:

1)薪资高于平均值的雇员名单;
2)同一天生日的雇员名单。

1.
select * from staff where salary>(select avg(salary)from staff);
2.
select distinct a.[name],a.birthday from staff a,staff b
where a.birthday=b.birthday and a.staff_id!=b.staff_id

1.select * from staff
where salary>(select avg(salary) from staff)
2.select distinct * from staff a
where exists(select * from staff b
where b.[staff_id]<>a.[staff_id] and b.birthday=a.birthday)

1.1select * from staff where salary>
(select avg(salary) from staff)
2.select * from staff where birthday in(
select birthday from staff groupy by birthday where count(birthday)>2)
不知道会不会错。。