1樓:匿名使用者
假設學生表為
a,學號欄位為id,姓名欄位為name;
課程表為b,其中row_id為課程編號,stu_no為選修該門課的學生的學號
sql:
select a.id,a.name
from a
where a.id not in (select distinct b.stu_no from b)
2樓:匿名使用者
應為三張表:
學生表a 課程表b 選修表c(cid aid bid)--沒有選修任何課程的學生的學號
select * from a where aid not in(select distinct aid from c) --為已選修的人
如有問題可以追問,我當及時回答.
希望能幫到你!
3樓:抽插小旋風
select 學號,姓名 from 表 where 選修課程 is null
或者select 學號,姓名 from 表 where 選修課程 =『』
怎樣用sql語言在資料庫查詢沒有選修任何課程學生的學號和姓名?
4樓:匿名使用者
假設學生表為a,學號欄位為id,姓名欄位為name;
課程表為b,其中row_id為課程編號,stu_no為選修該門課的學生的學號
sql:
select a.id,a.name
from a
where a.id not in (select distinct b.stu_no from b)
資料庫中,用sql語言如何查詢沒有選修1號課程的學生姓名
5樓:哈皮的小逗比
student--學生表
student_id,
student_name,
student_no
course--課程表
course_id,
course_name
sc--選課資訊表
student_id,
course_id
select *
from student
where student_id not in(select student_id
from sc
where course_id in
(select course_id from course where course_name = '1號課程'))
6樓:冉涵陽翁雋
假設學生表為a,學號欄位為id,姓名欄位為name;
課程表為b,其中row_id為課程編號,stu_no為選修該門課的學生的學號
sql:
select
a.id,a.name
from
awhere
a.id
notin
(select
distinct
b.stu_no
fromb)
7樓:匿名使用者
select sname
from student
where not exists
(select *
from sc
where student.sno=sc.sno and **o='1');
sql資料庫中查詢選修了所有課程的學生的學號和姓名及選修門數
8樓:騰訊電腦管家
select s.sname, s.s*** , s.
sage, s.sdept c.**ame g.
grade from student s , course c ,grade g where s.sno = g.sno and g.
**o = c.**o;
9樓:站在風中望著你
??????????????????????????你好,sql是什麼
如何用sql語言在資料庫中查詢沒有選修任何課程的學生的學號,姓名的命令?
10樓:匿名使用者
假設學生表為
a,學號欄位為id,姓名欄位為name;
課程表為b,其中row_id為課程編號,stu_no為選修該門課的學生的學號
sql:
select a.id,a.name
from a
where a.id not in (select distinct b.stu_no from b)
資料庫sql語句中 查詢選修了全部課程的學生的學號和姓名 理解
11樓:匿名使用者
這思路是用了個雙重否定來求解的。因為sql中沒有全稱量詞,於是要把題目轉換成等價的存在量詞表達形式。即根據(∀x)p≡¬∃(¬p)來轉化為雙重否定的表達。
同時由於「學生x選修課程y 」
之間是不定的,需要使用兩個exist。
於是「選修了全部課程的學生」等價於「不存在(有他沒選的課的)學生」
使用了兩次not exists來實現雙重否定。
先查詢在課程裡查詢「沒有學生選的課程」,第一次否定,
然後再在學生裡查詢「沒有屬於上面情況的學生」的名字,第二次否定;
結合起來,就是 「沒有(沒選的課程)的學生」了。
好了,從裡到外寫出來,就是
select sname from student where not exists(
select * from course where not exists(
select * from sc where sno=student.sno and **o=course.**o
))這個只不過是逆向思維來解決問題的方法。舉一反三,比如要查「被全部學生都選的課程名」
則是求「不存在有學生沒選它的課程」
select **ame from course where not exists(
select * from student where not exists(
select * from sc where sno=student.sno and **o=course.**o
))再如,查「所有人都沒選修的課程」,這個雖然是單次否定了,但仍需要兩個存在量詞表述。
等價於查詢「不存在有學生選了它的課程」。
select **ame from course where not exists (
select * from student where exists (
select * from sc where **o=course.**o and sno=student.sno))
12樓:風嘯無名
沒有資料庫難以具體說明,總的來說,就是一個多表查詢包括學生基本資訊表、課程資訊表、成績表等,學號為主鍵,查詢姓名和課程、分數等資訊,總分用sum算。
1 。 exists 子查詢找到的提交
not exists 子查詢中 找不到的提交說明:不要去翻譯為存在和不存在,把腦袋搞暈。
2 。 建立程式迴圈的概念,這是一個動態的查詢過程。如 for迴圈 。
3 。 exists執行的流程exists首先執行外層查詢,再執行記憶體查詢,與in相反。 流程為首先取出外層中的第一元組, 再執行內層查詢,將外層表的第一元組代入,若內層查詢為真,即有結果時。
返回外層表中的第一元 組,接著取出第二元組,執行相同的演算法。一直到掃描完外層整表 。
13樓:月光雪松
樓主彆著急!
為好理解我們先從這條sql語句所要實現的功能入手。
功能:查出選修了全部課程的學資訊。那麼sql在查詢資料的時候的遍歷每一個學生資訊。判斷該學生是否滿足條件。
1 如果存在這麼一條course記錄a(暫命名為a), 則不選擇該學生。否則該學生就被查詢出來
2 那麼記錄a,是怎麼查出來的呢?a查出的條件是:不存在sc記錄b,只要不存在b,就可查出a
3 那麼b記錄是什麼?b記錄是選課資訊表,根據學號和課程號可查出記錄b
如果b為空(該學生有沒有選的課程)也就是不存在,則a就有一條記錄,根據規則2可知:因為有a,所以該學生資訊將不被輸出。
如果在sc中每一個課程編號和該學生編號為條件都能夠查出一條記錄b(也就是該學生選修了全部課程),所以a記錄不存在,則輸出該學生的資訊。
也就是在選課表中,如果學生選了全部課程(也就是滿足select * from sc where sno= student.sno and **o= course.**o)始終存在,當然,課程編號是任意的)。
那麼就輸出該學生的資訊。你不要為理解這條sql而忘記了它本身是要做什麼.
帶著sql的目的(要實現的功能)去理解就好了。
14樓:雨夜的緣分
1,select * from sc where sno= student.sno and **o= course.**o
在sc表中查詢符合sno= student.sno and **o= course.**o這兩個條件的所有資料,
2,select * from course where not exists (select * from sc where sno= student.sno and **o= course.**o);這句的意思是在course表中查詢不滿足1,中的所有資料
3,select sname from student where not exists (select * from course where not exists (select * from sc where sno= student.sno and **o= course.**o));
這整句的意思就是查詢student表中所有不滿足2,資料,就是選修了全部課程的學生了
只所以會有這麼多查詢,可能sno= student.sno and **o= course.**o這兩個條件是是sc表查詢的條件分散在另外兩個表中,引用了雙重否定,也就是肯定的意思,達到可以讓student.
sno ,course.**o,在sc表中作為條件的目的
夠詳細吧!!!!
資料庫 查詢所有沒選修「0401010103」課程的學生學號及姓名
15樓:匿名使用者
select stud_id,name
from table
where course_id<>'0401010103'
sql查詢沒有選修1號課程的學生姓名
16樓:匿名使用者
select sname
from student
where not exists
(select *
from sc
where student.sno=sc.sno and **o='1');
17樓:匿名使用者
select [姓名(sname)] from student where not exists (select *
18樓:匿名使用者
from sc where sno=student.[學號(sno)] and **o='1');
用sql語句查詢選修了3門及以上課程的學生學號,姓名,選修的課程數
sql怎樣跨資料庫查詢,sql怎樣跨資料庫查詢oracle
使用dblink。例如 當前使用的資料庫是orcl1 要查詢的資料庫是orcl2的scott使用者的表。create public database link orcl2 scott connect to scott identified by tiger using description add...
如何在textBox中顯示在資料庫中查詢到的資料C
textbox.text ds.tables 0 rows 這裡面是表的第幾行,一般是0 這裡是表的第幾列 tostring this.textbox.text ds.tables 0 rows 0 這寫需要顯示的欄位的名稱 tostring 如何將資料庫資訊顯示到c textbox控制元件裡 是不...
在oracle資料庫中如果查詢資料庫中有哪幾張表
分兩種情況,一種是查詢當前使用者下的表,另一種是查詢當前資料庫下所有的表。查詢當前使用者的表 select table name from user tables 查詢當前資料庫下所有的表 select from user tables 查詢當前使用者的表 select from all table...