select student.* from student WHERE student.s_name not in( select st.s_name, st.s_id, st.s_birth from teacher t, student st, course c, score sc WHERE st.s_id=sc.s_id AND sc.c_id=c.c_id and c.t_id=t.t_id and t.t_name ="张三")
时间: 2024-02-28 22:54:22 浏览: 18
这个 SQL 查询语句的意思是从 student 表中选择所有的列,但是只取那些 s_name 不在子查询结果集中的记录。子查询中选择了四个列,而在 not in 中只能选择一个列。因此,你需要修改子查询,只选择 s_name 列,如下所示:
```
select student.* from student WHERE student.s_name not in( select st.s_name from teacher t, student st, course c, score sc WHERE st.s_id=sc.s_id AND sc.c_id=c.c_id and c.t_id=t.t_id and t.t_name ="张三")
```
这样就只在 not in 中选择了一个列,可以正确执行查询语句了。
相关问题
select s.s_name , s.s_birth ,s.s_sex,sc.s_score from (select s_id, c_id, s_score, row_number() over(distribute by c_id sort by s_score desc) rowNum from score) sc left join student s on s.s_id = sc.s_id where sc.rowNum between 2 and 3;
这是一个 SQL 查询语句,用于查询学生表和成绩表中的信息。具体来说,它使用了子查询和窗口函数,以及左连接和条件筛选。
子查询部分是:
```
select s_id, c_id, s_score,
row_number() over(distribute by c_id sort by s_score desc) rowNum
from score
```
这个子查询用于给每个课程按照成绩从高到低排序,并为每个学生的排名添加一个行号。其中,`distribute by c_id` 表示按照课程 ID 进行分组,`sort by s_score desc` 表示按照成绩倒序排序。
主查询部分是:
```
select s.s_name, s.s_birth, s.s_sex, sc.s_score
from (子查询) sc
left join student s on s.s_id = sc.s_id
where sc.rowNum between 2 and 3
```
这个主查询使用了左连接,将学生表和子查询结果按照学生 ID 进行连接,并筛选出排名为第二和第三的学生信息。最终,查询结果包括学生姓名、出生日期、性别和对应课程的成绩。
–1.学生表 Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id,c_name,t_id) – --课程编号, 课程名称, 教师编号 –3.教师表 Teacher(t_id,t_name) --教师编号,教师姓名 –4.成绩表 Score(s_id,c_id,s_score) --学生编号,课程编号,分数查询各科成绩前三名的记录 -- 1.选出b表比a表成绩大的所有组 -- 2.选出比当前id成绩大的 小于三个的 select a.s_id,a.c_id,a.s_score from sc
Sure! You can achieve the desired result by using the following SQL query:
```sql
SELECT a.s_id, a.c_id, a.s_score
FROM Score a
WHERE (SELECT COUNT(*)
FROM Score b
WHERE b.c_id = a.c_id AND b.s_score > a.s_score) < 3;
```
This query will select the `s_id`, `c_id`, and `s_score` from the `Score` table where the count of records with a higher score for the same course is less than 3.