用SQL查詢同時選修了1號課和2號課的學生學號怎麼查

2021-04-14 11:16:42 字數 3138 閱讀 3741

1樓:吳

你好像寫來錯了吧自,,,

我感覺應該是

select sno

from sc

where cno='1' and son in (select sno from sc where cno='2');

或者where cno='1' intersert select sno from sc where cno='2');

intersect對兩個查詢做交集。相當於and

用sql查詢同時選修了1號課和2號課的學生學號

2樓:於曉楠買甘

查詢bai

同時選修了1號和2號課的學du生學號

涉及到兩zhi個表.學生表和dao課程表

語句:select

*from

student

inner

join

scon

student.sno=sc.sno

andcno

in('1','2')

為什麼不用內where

cno=』1『

andcno=』2『

這個關係到資料容庫的優化問題,哪個執行快,就寫哪個那個語句也可以這樣寫啊where

snoin

(select

snofrom

scwhere

sno=』1『

)and

snoin(select

snofrom

scwhere

sno=』2『)

3樓:吳

你好抄像寫錯了吧,襲

,,我感覺應該是bai

select sno

from sc

where cno='1' and son in (select sno from sc where cno='2');

或者where cno='1' intersert select sno from sc where cno='2');

intersect對兩個du查詢zhi做交集。相當於daoand

4樓:envy誒

因為這樣的意思是 在一行內課號既得等於1又得等於2 並沒有這樣的

5樓:匿名使用者

sno 指的是什麼?

baicno指什麼? 上面的sql語句du是不可能zhi實現同樣的功能的。

sno如果是指dao學生學號;版

cno是指課程號的權

話。where cno=』1『 and cno=』2『是指課程號是1和2 的學生資訊。

where sno=』1『 and sno in(select sno

from sc

where sno=』2『)

是指學生學號是1和2 的學生,事實上,作為主鍵的sno沒有可能同時是1和2的。

請採納答案,支援我一下。

sql查詢沒有同時選修1號課程和2號課程學生的學號

6樓:匿名使用者

select distinct sno

from sc

where sno not in

(select sno

from sc

where cno='1' and sno in(select sno

from sc

where cno='5'))

這是一般的變法,還可用集合查詢,關鍵字intersectselect distinct sno

from sc

where sno not in

(select sno

from sc

where cno='1'

intersect

select sno

from sc

where cno='5')

7樓:匿名使用者

select s.學號

from student s,course c,sc scwhere s.學號=sc.學號 and c.課程號=sc.課程號 and

c.課程號='1'

union

select s.學號

from student s,course c,sc scwhere s.學號=sc.學號 and c.課程號=sc.課程號 and

c.課程號='2'

8樓:凌動小生

select distinct sc.sno where sc.cno !='課程1'and sc.cno !='課程2'

9樓:匿名使用者

select sno where [sc] cno='選修1號' and cno='選修2號' order by sno

sql查詢沒有選修1號課程的學生姓名

10樓:匿名使用者

select sname

from student

where not exists

(select *

from sc

where student.sno=sc.sno and cno='1');

11樓:匿名使用者

select [姓名(sname)] from student where not exists (select *

12樓:匿名使用者

from sc where sno=student.[學號(sno)] and cno='1');

sql資料庫中查詢選修了所有課程的學生的學號和姓名及選修門數

13樓:騰訊電腦管家

select s.sname, s.s*** , s.

sage, s.sdept c.cname g.

grade from student s , course c ,grade g where s.sno = g.sno and g.

cno = c.cno;

14樓:站在風中望著你

??????????????????????????你好,sql是什麼

SQL查詢選修了全部課程的學生姓名

第一問 兩個not exists表示雙重否定 沒有一個選了課的學生沒有選course表裡的課程 select sname from student where not exists 沒有一個學生滿足以下條件 select from course where not exists 什麼條件呢?沒有選過...

查詢選修了2號課程的學生的學號,用SQL查詢同時選修了1號課和2號課的學生學號

select distinct sno from sc where cno c02 請根據具體的資料庫對sql語句作出適當的修改!用sql查詢同時選修了1號課和2號課的學生學號 查詢bai 同時選修了1號和2號課的學du生學號 涉及到兩zhi個表.學生表和dao課程表 語句 select from ...

sql兩個表多列聯合查詢,sql語句 同時查詢兩個表

select a.b.備註 from select 姓名,一班,一班 as 班級 from 課程 表 union all select 姓名,二班,二班 as 班級 from 課程 表 union all select 姓名,三班,三班 as 班級 from 課程 表 a left join 流水錶...