(6)select學號,姓名from學生表a,選課表bwherea.學號=b.學號
and課程號'5'
(7)select學號from選課where課程號notin('5')
(8)select學號from選課where課程號in('5','6')
(9)select學號,姓名from學生表a,選課表bwherea.學號=b.學號
and課程號in(select課程號from課程表)
(10)select學號,姓名from學生表a,選課表bwherea.學號=b.學號
and課程號in(select課程號from選課表where學號='95001')
Ⅱ 怎麼用SQL語句查詢 例如 查詢選修課 『稅收』 的姓名和編號
你好,尊敬的網路知道用戶摟主,很願意為你問題作答
建議你首先找一本SQL命令集看看,SQL srever 2000 [安裝之後,會有一個聯機從書,那裡面可謂詳盡的講述了SQL命令,注意:SQL server 2000與SQL命令是重大區別的.SQL是結構化查詢設計語言的縮寫,:SQL server 2000則是微軟的關系資料庫產品,一切關系資料庫都是依賴SQL的.這當然要看資料庫內建了多少SQL命令,ACCESS和,SQL srever 2000 都接受SQL命令的操作,但是操作ACCESS的SQL命令和語句,幾乎可以不加修改的用於SQL server ,但是反過來不行,比如ACCESS根本就不支持使用case語句等.
SQL命令並不很多,百十個而已,但是操作起資料庫來,幾乎是達到出神入畫的地步.用人工可以需要幾天的時間才能弄到結果,用SQL命令只不過是彈指之間.
想擺弄資料庫,你不學SQL,就等於想學洋文,但不認識ABC字母一樣.
SQL srever 2000 的聯機從書中Transact-SQL參考一章,介紹了全部的SQL命令和符號.在其它章節還介紹很多SQL語句的寫法以及SQL命令的用法.好好學吧
你們是年輕人,精力正旺,弄一可以讀電子書的手機,把這部聯機從書弄成文本文件,放在手機中,隨時看看,比你看那些無聊的網上小說,有意義的多.
Ⅲ 使用標准SQL嵌套語句查詢選修課程名稱為』稅收基礎』的學員學號和姓名
以我學習SQL的經驗,這樣應該就可以了select S.S#, SN from S, C, SC Where S.S#=SC.S# and C.C#=SC.C# and C.CN='稅收基礎';
Ⅳ 資料庫稅務管理系統SQL語言
SQL是高級的非過程化編程語言,允許用戶在高層數據結構上工作。他不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統可以使用相同的SQL語言作為數據輸入與管理的介面。它以記錄集合作為操縱對象,所有SQL語句接受集合作為輸入,返回集合作為輸出,這種集合特性允許一條SQL語句的輸出作為另一條SQL語句的輸入,所以SQL語言可以嵌套,這使他具有極大的靈活性和強大的功能,在多數情況下,在其他語言中需要一大段程序實現的一個單獨事件只需要一個SQL語句就可以達到目的,這也意味著用SQL語言可以寫出非常復雜的語句。
Ⅳ 關於SQL語句的問題
[s#]就是代表學號,加[]沒有其他意思,這是查詢語法的寫法,例如:SELECT[DISTINCT] (column [{, columns}])| * FROM table [ {, table}] [ORDER BY column [ASC] | DESC [ {, column [ASC] | DESC }]]。因為你要求查詢的是學員的學號和姓名,s#代表學號、sn代表姓名。所以應該是SELECT SN,S#。sd確實是它寫錯了,SD代表單位,按給出的答案查詢出來的結果就是選修課名稱為「稅收基礎」的學院姓名和單位。
Ⅵ SQL測試題(註:最佳答案必須能在MySQL下運行)
/*
閑著沒事,瞅瞅網路上的問題,今天天晚了,先解決一個,另一個明兒個再說了!
第二道題也算已經搞定了!
環境 : mysql Ver 14.12 Distrib 5.0.45, for Win32 (ia32)
參考 :
exist與in 的區別
http://blog.csdn.net/change888/archive/2008/03/31/2232778.aspx
*/
/*********************************問題 1 **************************************/
drop table if exists s;
create table if not exists s (s varchar(32), sn varchar(32), sd varchar(32),
sa int);
insert into s values ('s1', '朱', '開發本部', 23);
insert into s values ('s2', '牛', '人事部', 25);
insert into s values ('s3', '楊', '財務部', 26);
insert into s values ('s4', '馬', '開發本部', 22);
insert into s values ('s5', '呂', '人事部', 27);
insert into s values ('s6', '於', '開發本部', 28);
insert into s values ('s7', '侯', '開發本部', 28);
drop table if exists c;
create table if not exists c (c varchar(32), cn varchar(32));
insert into c values ('c1', '軟體工程');
insert into c values ('c2', '計算機技術與科學');
insert into c values ('c3', '車輛工程');
drop table if exists sc;
create table if not exists sc (s varchar(32), c varchar(32));
insert into sc values ('s1', 'c1');
insert into sc values ('s1', 'c2');
insert into sc values ('s1', 'c3');
insert into sc values ('s2', 'c1');
insert into sc values ('s2', 'c3');
insert into sc values ('s3', 'c2');
insert into sc values ('s4', 'c2');
insert into sc values ('s4', 'c3');
insert into sc values ('s5', 'c1');
insert into sc values ('s6', 'c3');
/* 1. 查詢選修課程名稱為 「軟體工程」 的學員學號和姓名 */
select s.s '學號', s.sn '姓名' from s where s.s in
(select sc.s from sc where sc.c in
(select c.c from c where c.cn = '軟體工程'));
/* 2. 查詢選修課程編號為 「C2」 的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where s.s in
(select sc.s from sc where sc.c = 'C2');
/* 3. 查詢選修課程編號 不 為 「C2」 的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where
s.s not in (select sc.s from sc where sc.c = 'C2')
and
s.s in (select sc.s from sc);
/* 4. 查詢選修全部課程的學員姓名和所屬單位 */
select s.sn '姓名', s.sd '所屬單位' from s where
(select count(DISTINCT sc.c) from sc where sc.s = s.s)
=
(select count(DISTINCT c.c) from c );
/* 5. 查詢選修了課程的學員人數 */
select count(DISTINCT sc.s) '人數' from sc;
/* 6. 查詢選修課程 >= 2 門的學員學號和所屬單位 (不得不用 CASE 語句了)*/
select s.sn '姓名', s.sd '所屬單位' from s where s.s in
(select CASE WHEN count(DISTINCT sc.c) >=2 THEN sc.s END from sc group by sc.s );
/* 運行結果
------------------------------------1
+------+------+
| 學號 | 姓名 |
+------+------+
| s1 | 朱 |
| s2 | 牛 |
| s5 | 呂 |
+------+------+
------------------------------------2
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
| 楊 | 財務部 |
| 馬 | 開發本部 |
+------+----------+
------------------------------------3
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 牛 | 人事部 |
| 呂 | 人事部 |
| 於 | 開發本部 |
+------+----------+
------------------------------------4
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
+------+----------+
------------------------------------5
+------+
| 人數 |
+------+
| 6 |
+------+
------------------------------------6
+------+----------+
| 姓名 | 所屬單位 |
+------+----------+
| 朱 | 開發本部 |
| 牛 | 人事部 |
| 馬 | 開發本部 |
+------+----------+
*/
/*********************************問題 2 **************************************/
drop table if exists s ;
create table if not exists s ( sno varchar(32), sname varchar(32));
insert into s values ('s1', '朱');
insert into s values ('s2', '牛');
insert into s values ('s3', '楊');
insert into s values ('s4', '馬');
insert into s values ('s5', '呂');
insert into s values ('s6', '於');
insert into s values ('s7', '侯');
drop table if exists c;
create table if not exists c ( cno varchar(32), cname varchar(32),
cteacher varchar(32));
insert into c values ('c1', '數學', '張');
insert into c values ('c2', '日語', '李'); /*假設李老師同時教授日語和英語*/
insert into c values ('c3', '英語', '李');
drop table if exists sc;
create table if not exists sc (sno varchar(32), cno varchar(32),
scgrade double);
insert into sc values ('s1', 'c1', 75);
insert into sc values ('s1', 'c2', 70);
insert into sc values ('s1', 'c3', 80);
insert into sc values ('s2', 'c1', 50);
insert into sc values ('s2', 'c3', 40);
insert into sc values ('s3', 'c1', 50);
insert into sc values ('s3', 'c2', 60);
insert into sc values ('s4', 'c1', 90);
insert into sc values ('s4', 'c2', 40);
insert into sc values ('s4', 'c3', 20);
insert into sc values ('s5', 'c1', 80);
insert into sc values ('s6', 'c1', 85);
/* 1. 沒有 選 修過「李」老師講授課程的所有學生姓名 */
select s.sname '姓名' from s where s.sno not in
(select sc.sno from sc where sc.cno in
(select c.cno from c where c.cteacher = '李'));
/* 2. 列出有二門以上(含兩門)不及格課程的學生姓名及其平均成績 */
select s.sname '姓名', AVG(sc.scgrade) '平均成績' from s, sc
where s.sno = sc.sno
and
(select count(sc.sno) from sc where sc.sno = s.sno
and sc.scgrade < 60 ) >= 2
group by s.sno;
/* 3. 列出既學過「C1」號課程,又學過「C2」號課程的所有學生姓名 */
select s.sname '姓名' from s where s.sno in
(select t1.sno from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1' and t2.cno = 'c2');
/*或者*/
select s.sname '姓名' from s where s.sno in
(select sc.sno from sc where sc.cno = 'c1' and sc.sno in
(select t1.sno from sc t1 where t1.cno = 'c2'));
/* 4. 列出「C1」號課成績比「C2」號同學該門課成績高的所有學生的學號 */
select t1.sno '學號' from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1'
and t2.cno = 'c2' and t1.scgrade > t2.scgrade;
/* 5. 列出「C1」成績比「C2」成績高的學生的學號及其「C1」和「C2」的成績 */
select t1.sno '學號', t1.scgrade 'C1成績', t2.scgrade 'C2成績' from sc t1, sc t2
where t1.sno = t2.sno and t1.cno = 'c1'
and t2.cno = 'c2' and t1.scgrade > t2.scgrade;
/* 運行結果
------------------------------------1
+------+
| 姓名 |
+------+
| 呂 |
| 於 |
| 侯 |
+------+
------------------------------------2
+------+----------+
| 姓名 | 平均成績 |
+------+----------+
| 牛 | 45 |
| 馬 | 50 |
+------+----------+
------------------------------------3
+------+
| 姓名 |
+------+
| 朱 |
| 楊 |
| 馬 |
+------+
------------------------------------4
+------+
| 學號 |
+------+
| s1 |
| s4 |
+------+
------------------------------------5
+------+--------+--------+
| 學號 | C1成績 | C2成績 |
+------+--------+--------+
| s1 | 75 | 70 |
| s4 | 90 | 40 |
+------+--------+--------+
*/
Ⅶ 資料庫sql語句查詢題目,求解
select case when a > b then a else b end,
case when b > c then b else c end
from t
Ⅷ 請設計sql語句,查詢徵收表中「經濟性質」及相應的納稅人數量
你是什麼資料庫啊?sqlserver嗎?還是access?還是其他資料庫?sqlserver有那個sqlservermanagerstudio,可以創建表老的版本用的是查詢分析器ACESS2007(1)點擊「創建」--點擊「查詢設計」(2)點擊關閉(3)點擊左上角的"SQL視圖"就可以打開SQL窗口了2、ACCESS2003(1)點擊對象里的「查詢」(2)點擊「在設計視圖創建查詢」,再點擊「關閉」(3)再點擊左上角的"sql"(4)就可以輸入sql語句了
Ⅸ 哪位大蝦有經典的sql三表聯查的習題呢,我面試需要,急需沖沖電啊,比如 像學生,課程,分數,這種三表之
1.創建資料庫
Createdatabasesc
2.創建學生表
createtable學生(
學號intprimarykey,
姓名varchar(10)notnull,
性別set('男','女')notnull,
出生年月datenotnull
);
3.創建課程表
Createtable課程(
課程編號int,
課程名varchar(10),
學分int,
Primarykey(課程編號)
);
4.創建成績表
Createtable成績(
學號intnotnull,
課程編號int,
成績int,
Primarykey(學號,課程編號),
Foreignkey(課程編號)references課程(課程編號),
Foreignkey(學號)references學生(學號)
);
select*from成績Ainnerjoin學生BonA.學號=B.學號innerjoin課程ConA.課程編號=C.課程編號
Ⅹ 這個sql語句怎麼寫題目如下:
SELECT S#,SN FROM SC,S,C
WHERE SC.S#=S.S#
AND SC.C#=C.C#
AND C.CN='稅收基礎』
AND SC.G>G1