当前位置: 代码迷 >> Sql Server >> sql疑难杂症解决方案
  详细解决方案

sql疑难杂症解决方案

热度:84   发布时间:2016-04-27 17:53:44.0
sql疑难杂症
数据库如下

name       kc         fs
A           语文       65
A           数学       66
B           语文       55
B           数学       86
C           语文       64
C           数学       66
A           英语       66


用一条sql语句查出所有kc的fs大于60的学生的姓名


------解决方案--------------------
create table student(name varchar(10),kc varchar(10),fs int)
insert into student
select 'A ', '语文 ',65
union all select 'A ', '数学 ',66
union all select 'B ', '语文 ',55
union all select 'B ', '数学 ',86
union all select 'C ', '语文 ',64
union all select 'C ', '数学 ',66
union all select 'A ', '英语 ',66

select name
from student
group by name
having count(*)=(select count(*) from student t where student.name=t.name and t.fs> 60)
------解决方案--------------------
暈,理解錯了。


Select * From TableName A
Where Not Exists(Select * From TableName Where name = A.name And fs <= 60)
  相关解决方案