當前位置:首頁 » 編程語言 » sql聯系

sql聯系

發布時間: 2022-01-08 10:21:24

❶ 求幾個sql文件,就是有數據的,拿來練習SQL語句

郵件已經發出,過幾分鍾後記得查收(可能在垃圾箱里邊),收到後覺得還算滿意請點下邊的採納通知我。如果10分鍾後還沒收到,請直接在本問題里追問我,我會再次發送。
如果還有需要的朋友,請點「贊」此條回答以後,在下面的評論里留下您的聯系方式即可!
最後如果在採納之餘能加點分數,那就更好啦!

❷ 誰有sql 語句練習題,越多越好!

額 我只曉得SQLServer的T-SQL
中文版SQL Server 2000開發與管理應用實例
http://www.china-pub.com/26313
都是大量項目中能用到的實例
CSDN SQL大版主的書籍,可說非常不錯了
希望對你有幫助

如果還要再深入理解點原理東西
可以看下 微軟技術叢書sql2005 T-SQL查詢與T-SQL程序設計

❸ SQL入門怎麼練習

自己安裝一個SQL SERVER然後按照書上的一點一點執行,先從最基本的開始

❹ 想學習SQL語言,該用什麼軟體來練習SQL語句

電腦上裝個Mysql。然後再裝Navicat for MySQL
或者SQLyog這個csdn上也有漢化的

❺ 如何在一台電腦上練習SQL語句

1.選擇你想安裝的 sql2000。或是sql 2005

2.安裝成功後,打開sql server 服務管理器,然後開啟

3.企業管理器 然後 就可以 創建資料庫 表了

4.也可以在 查詢分析器裡面 寫查詢語句,但是要找到 對應的資料庫 來查詢

❻ 想練習SQL,有沒有什麼網上資料庫是能直接拿來練習SQL的

建議安裝一個EasyAPM-Server v2.1.0 RC,你就可以隨便練習操作sql資料庫了。
地址:http://www.opticsky.cn/htm_data/37/0601/2347.html

❼ sql練習!!!

alter talbe stuscore
add constraint ch_a check(english<100 and english>0)
select * from stuinfo where name like '張%' and sex = '男'
select time from stuinfo where name = '劉k'
……………………
……………………
只能到這里了,僅供參考

❽ 我想練習sql語句,請問如何做呢

安裝一個資料庫伺服器,建立一個庫。
然後先做這些練習吧,語句都加了注釋了
/*
建立一個由3個文件組成的資料庫,資料庫名稱為test。
主數據文件邏輯名稱為test_data,物理文件名c:\test_data.mdf;
輔助數據文件邏輯名稱為test_data2,物理文件名c:\test_data2.ndf;
日至文件邏輯名稱為test_log,物理文件名c:\test_log.ldf;
所有文件初始尺寸為3mb,可以自動增長,最大尺寸為15mb。
*/
create database test on
primary
(
name=test_data,
filename='c:\test_data.mdf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
),
(
name=test_data2,
filename='c:\test_data2.ndf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
)
log on
(
name=test_log,
filename='c:\test_log.ldf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
)

/*
創建一個名為employees的表,該表由5個欄位組成:emp_id(員工編號)、ename(員工名稱)、
age(年齡)、title(職務)、salary(薪水)。其中emp_id為該表的主鍵。該表存放在主文件組。
*/
use test
go
CREATE TABLE employees(
emp_id char (4) primary key,
ename nvarchar (10) NOT NULL,
age tinyint NOT NULL,
title nvarchar (10) NULL,
salary money NULL,
) ON [PRIMARY]

--向employees表插入部分數據
insert into employees values('0001','楊建新','22','經理','3000')
insert into employees values('0002','楊建新','23','職員','4000')
insert into employees values('0003','楊建新','24','總經理','5000')
insert into employees values('0004','楊建新','26','職員','2000')

--創建備份設備test_bak,其位置為c:\backup\test_bak.bak
sp_admpdevice 'disk','test_bak','c:\backup\test_bak.bak'

--建立資料庫test的完整備份到備份設備test_bak,並命名為test_full_bak1
backup database test to test_bak with name='test_full_bak1'

--向employees表插入新數據
insert into employees values('0005','王建新','24','總經理','1000')
insert into employees values('0006','劉建新','26','職員','2000')

--執行test資料庫的事務日誌備份,該備份追加到備份設備test_bak,命名為test_log_bak1
backup log test to test_bak with name='test_log_bak1'

--截斷employees表,清空內容(記錄此時的時間)
truncate table employees

--備份資料庫的尾部日誌
use master
go
backup log test to test_bak with name='test_log_recovery',norecovery

--恢復資料庫的完整備份,並且不要執行還原進程(norecovery)
restore database test from test_bak with file=1,norecovery

--恢復第一個日誌備份,如果此時執行recovery,將得到所有數據
restore log test from test_bak with file=2,recovery

--如果執行上述語句時,使用norecovery選項,則可以繼續恢復第二個日誌備份,即尾部日誌
restore log test from test_bak with file=2,norecovery
restore log test from test_bak with file=3,recovery

--如果按照上述操作,則恢復完成後employees表中沒有任何數據,因為尾部日誌中包含清空表的操作
--若要恢復所有數據,也可以恢復到時間點到清空時間之前
restore log test from test_bak with file=3,stopat='2008-11-16 11:25:00'

--添加一個名為mike,密碼為123456的login賬戶,該賬戶的默認資料庫為northwind
sp_addlogin 'mike','123456','northwind'
--切換到northwind資料庫
use northwind
go
--將登錄賬戶mike映射為當前資料庫中的用戶
sp_grantdbaccess 'mike','mike' --或:sp_adser 'mike','mike'
--建立資料庫角色accessdata
sp_addrole tablecreate
--為資料庫角色tablecreate賦予創建表的許可權
grant create table to tablecreate
--將用戶mike加入到角色tablecreate中
sp_addrolemember 'tablecreate','mike'
--賦予用戶mike對procts表的插入數據許可權
grant insert on procts to mike
--撤銷用戶mike對procts表的許可權
revoke insert on procts from mike
--察看角色信息
sp_helprole tablecreate
--察看角色包括的成員
sp_helprolemember tablecreate
--在角色tablecreate中刪除成員mike
sp_droprolemember 'tablecreate','mike'
--刪除角色tablecreate
sp_droprole tablecreate
--刪除資料庫用戶賬戶
sp_revokedbaccess 'mike'
--刪除登錄帳號
sp_droplogin 'mike'

❾ SQL練習題

一 學生 – 課程資料庫
1 查詢 7號課程沒有考試成績的學生學號
select sno from sc where cno=』7』 and grade is not null
2 查詢 7號課程成績在90分以上或60分以下的學生學號
select sno from sc where grade>90 or grade<60
3 查詢課程名以「數據」兩個字開頭的所有課程的課程號和課程名。
Select cno,cname from c where cname like 『數據%』
4 查詢每個學生所有課程的平均成績,輸出學生學號、平均成績
select sno,avg(grade) from sc group by sno
5 查詢每門課程的選修人數,輸出課程號、選修人數。
Select cno,count(*) from sc group by cno
6 查詢選修 7號課程的學生的學號、姓名、性別。
Select s.sno, sname,ssex from s , sc where s.sno=sc.sno and cno = 『7』
7 查詢選修7號課程學生的平均年齡。
Select avg(sage) from s , sc where s.sno=sc.sno and cno = 『7』
8 查詢由30名以上學生選修的課程號。
Select sno from sc group by cno having count(*)>30
9 查詢至今沒有考試不及格的學生學號
a: select sno from s where sno not in ( select sno from sc where grade<60 )
b: select sno from sc group by sno having min(grade)>=60

1 找出選修課程號為 C2 的學生學號與成績。
Select sno,grade from sc where cno=』C2』
2 找出選修課程號為C4 的學生學號與姓名。
Select s.sno , sname from s,sc where s.sno=sc.sno and cno=』C4』
3 找出選修課程名為 Maths 的學生學號與姓名。
Select s.sno ,sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and cname = 『Maths』
4找出選修課程號為C2或C4 的學生學號。
Select distinct sno from sc where cno in (『C2』,』C4』)
或: Select distinct sno from sc where cno=』C2』 or cno =』C4』
5找出選修課程號為C2和C4 的學生學號。
Select sno from sc where cno =』C2』 and sno in (
select sno from sc where cno = 『C4』 )
6 找出不學C2課程的學生姓名和年齡
select sname , sage from s where sno not in ( select sno from sc where cno=』C2』 )
或:
select sname , sage from s where not exists ( select * from sc where sc.sno=s.sno and cno=』C2』 )
7 找出選修了資料庫課程的所有學生姓名。(與3同)
Select s.sno ,sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and cname = 『資料庫』

8 找出資料庫課程不及格的女生姓名
嵌套:
select sname from s where ssex = 『女』 and sno in ( select sno from sc where grade<60 and cno in ( select cno from c where cname=』資料庫』) )
連接:
Select sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and ssex=』女』 and cname = 『資料庫』 and grade<60
9 找出各門課程的平均成績,輸出課程名和平均成績
select cname , avg(grade) from sc , c where c.cno =sc.cno group by sc.cno
10找出各個學生的平均成績,輸出學生姓名和平均成績
select sname , avg(grade) from s , sc where s.sno=sc.sno group by sc.sno
11 找出至少有30個學生選修的課程名
select cname from c where cno in ( select cno from sc group by cno having count(*)>=30 )
12 找出選修了不少於3門課程的學生姓名。
Select sname from s where sno in ( select sno from sc group by sno having count(*)>=3)
13 找出各門課程的成績均不低於90分的學生姓名。
Select sname from s where sno not in ( select sno from sc where grade<90)
14* 找出資料庫課程成績不低於該門課程平均分的學生姓名。
Select sname from s where sno in (
Select sno from sc , c where sc.cno=c.cno and cname=』資料庫』 and
Grade > (Select avg(grade) from sc , c where sc.cno=c.cno and cname=』資料庫』 ) )
15 找出各個系科男女學生的平均年齡和人數。
Select sdept,ssex , avg(sage) , count(*) from s
Group by sdept , ssex
16 找出計算機系(JSJ)課程平均分最高的學生學號和姓名。
Select sc.sno , sname from s, sc where s.sno=sc.sno and sdept=』JSJ』
Group by sc.sno Having avg(grade) =
( Select top 1 avg(grade) from sc, s where s.sno=sc.sno and sdept=』JSJ』
group by sc.sno order by avg(grade) DESC )
三 客戶 – 商品資料庫中包括3按各表:KH,FP,YWY
1 查詢工資在 1000 到3000 元之間的男性業務員的姓名和辦公室編號。
Select Yname , Ono from YWY where salary between 1000 and 3000 and Ysex=』男』
2 查詢各個辦公室的業務員人數,輸出辦公室編號和對應的人數。
Select Ono , count(*) from YWY group by Ono
3 查詢每個客戶在2002年5月購買的總金額,輸出客戶號和相應的總金額。
Select Kno,sum(Fmoney) from FP where fdate between 『2002.5.1』 and 『2002.5.31』
Group by Kno
4 查詢2002年5月購買次數超過5次的所有客戶號,且按客戶號升序排序。
Select Kno from FP where fdate between 『2002.5.1』 and 『2002.5.31』
Group by Kno having count(*)>5
Order by Kno ASC
5 查詢各辦公室男性和女性業務員的平均工資。
Select Ono,Ysex ,avg(salary) from YWY group by Ono , Ysex
6 查詢2002年5月曾經在王海亮業務員手中購買過商品的客戶號、客戶姓名、聯系電話。
Select Kno,Kname,phone from KH where Kno in (
Select kno from FP where fdate between 『2002.5.1』 and 『2002.5.31』 and
Yno=(select Yno from YWY where Yname = 『王海亮』 )
7 查詢所有工資比1538號業務員高的業務員的編號、姓名、工資。
Select yno ,Yname, salary from YWY where salary >
( Select salary from YWY where Yno=』1538』 )
8 查詢所有與1538號業務員在同一個辦公室的其他業務員的編號、姓名。
Select Yno , Yname from YWY where Yno<>』1538』 and Ono in (
Select Ono from YWY where Yno=』1538』 )
9 查詢銷售總金額最高的業務員的編號。
Select Yno from FP Group By Yno Having sum(Fmoney) =
(Select top 1 sum(Fmoney) from FP group by Yno ORDER BY sum(Fmoney) DESC)
10 查詢所有業務員的編號、姓名、工資以及工資比他高的其他業務員的平均工資。
利用自身連接
Select y1.Yno ,y1.Yname ,y1.salary , avg( y2. salary) from YWY y1 , YWY y2
Where y1.Yno<>y2.Yno and y1.salary < y2.salary
Group by y1.Yno
Sno salary sno salary
1 100 1 100
2 120 2 120
3 90 3 90
4 110 4 110
四 某中學資料庫中由一張表:
學生選課表:由板及代碼、班內學號、姓名、科目、成績五個屬性組成,關系模式為
SC(BJDM,BNXH,XSXM,KM,CJ) ,其中(BJDM,BNXH)為主碼。
說明:每個學生每門科目存放一個記錄,科目有「語文」、「數學」、「外語」三門。
1 找出每個班級的班級代碼、學生人數、平均成績。
Select BJDM,count(*) ,avg(CJ) from SC group by BJDM
2 找出每個學生的班級代碼、學生姓名、考試科目數、總成績。
Select BJDM,XSXM,count(*) , sum(CJ) from SC
Group by BNXH
3 輸出一張表格,每位學生對應一條記錄,包括:班級代碼、姓名、語文成績、數學成績、外語成績。
方法一:利用視圖
create view v1 (bjdm,xsxm, yw,sx,wy ) AS
select bjdm , xsxm , cj , 0,0 from sc where km=』語文』
union
select bjdm , xsxm , 0 , cj,0 from sc where km=』數學』
union
select bjdm , xsxm , 0,0,cj from sc where km=』外語』

select bjdm, xsxm , sum(yw) as 語文, sum(sx) as 數學, sum(wy) as 外語 from v1 group by bjdm, xsxm
方法二:自身連接
select a.bjdm,a.xsxm , a.km,a.cj , b.km,b.cj , c.km,c.cj from sc a , sc b , sc c
where a.bjdm=b.bjdm and a.bnxh= b.bnxh and b.bjdm=c.bjdm and b.bnxh= c.bnxh
and a.km=』語文』 and b.km=』數學』 and c.km=』外語』
方法三:利用存儲過程(略)
4 輸出一張表格:由成績低於60分的每位學生對應一條記錄,包括欄位:班級代碼、姓名、最低成績。
Select bjdm,xsxm ,min(CJ) from sc where grade<60 group by bjdm,xsxm
5輸出一張表格:由成績低於60分的每位學生對應一條記錄,包括欄位:班級代碼、姓名、最高成績、平均成績。
得到平均成績:create view V1 (bjdm,bnxh ,avg_cj) AS
select bjdm,bnxh ,avg(cj) from sc where bjdm , bnxh
select sc.bjdm,sc.xsxm ,max(cj) , avg_cj from sc , V1
where sc.bjdm=v1.bjdm and sc.bnxh=V1.bnxh and cj<60
group by sc.bjdm,sc.xsxm
6輸出一張表格:所有成績不低於60分的每位學生對應一條記錄,包括欄位:班級代碼、姓名、平均成績。
select bjdm, xsxm , avg(cj) from sc
where sno not in ( select sno from sc where grade<60)
group by bjdm, xsxm
7輸出一張表格:每一位學生對應一條記錄,包括欄位:班級代碼、姓名、去掉一個最低分後的平均成績。
方法一:
得到每個學生的最低分:
create view V1 (bjdm,bnxh ,min_cj) as
select bjdm,bnxh,min(cj) from sc group by bjdm,bnxh
select sc.bjdm,sc.xsxm , avg(cj) from sc , v1
where sc.bjdm=v1.bjdm and sc.bnxh=v1.bnxh and sc.cj <> v1.min_cj
group by bjdm,bnxh
方法二:
select sc.bjdm,sc.xsxm , ( sum(cj) – min(cj) ) / count(*) from sc
group by bjdm , bnxh
8輸出一張表格:每門科目對應一條記錄,包括欄位:科目、去掉一個最低分後的平均成績。
方法一:
得到每門課的最低分:
create view V1 ( km, min_cj) as
select km,min(cj) from sc group by km
select sc.km , avg(cj) from sc , v1
where sc.km=v1.km and sc.cj <> v1.min_cj
group by sc.km
方法二:
select km , (sum( cj) – min(cj) )/count(*) from sc
group by km
補充9:輸出表格:每門科目對應一條記錄,包括欄位:科目、去掉一個最低分和最高分後的平均成績。
select km , (sum( cj) – min(cj) – max(cj) )/count(*) from sc
group by km
五 資料庫存放著某高校1990年以來英語四、六級的考試情況,且規定:
1 英語四、六級考試每年分別在6月和12月舉行二次;
2 四級沒有通過的學生不能報考六級;
3 某一級的考試只要沒有通過可以反復參加考試;
4 某一級的考試一旦通過就不能再報考同級的考試;
5 允許報了名但不參加考試。
該資料庫中有二張表,相應的關系模式如下:
學生表:S(Sno, Sname, Ssex, Sage, Sdept),其中Sno為主碼。
考試表:E(Sno, Year, Month, Level, Grade),學號、年、月、級別、成績。
其中(Sno, Year, Month)為主碼。
1. 找出各次四級和六級考試的參考人數和平均成績(報了名但沒有參加考試的不作統計)
select year , month,level ,count(*) , avg(grade)
group by year,month , level
2. 找出各次四級考試中平均分最高的系科(報了名但沒有參加考試的不作統計)。
A: Select sdept from s , e where s.sno=e.sno
Where level=4
Group by sdept
Having avg(grade)>=ALL(
Select avg(grade) from s , e where s.sno=e.sno where level=4 Group by sdept )
B: Select top 1 sdept from s , e where s.sno=e.sno
Where level=4
Group by sdept
Order by (avg(grade) desc
3. 找出已經通過英語六級考試的學生的學號、姓名和性別(用連接方法做)
select s.sno,sname,ssex from s,e
where s.sno=e.sno and level=6 and grade>=60
4. 找出在同一年中四、六級考試都參加了的學生的學號
1) select sno from E
where (level=4 and grade>=60) or level=6
group by year having count(*)>=2
2) select sno from E X where level=4 and grade>=60 and exists (
select * from E Y where Y.sno=X.sno and year=X.year and level=6 )
5. 找出只參加一次考試就通過了英語六級考試的學生的學號
select sno from E
where level=6
group by sno
having count(*)=1 錯,想想為何?
1) select sno from E
where level=6
group by sno
having count(*)=1 and max(grade)>=60
2) select sno from E where level=6 and grade>=60 and sno in (
select sno from E where level=6 group by sno having count(*)=1)
6. 找出至今沒有通過英語四級考試的學生的學號(應包括至今還沒有參加過考試或者是參加了但還沒有通過兩種)
select sno from E where level=4
group by sno
having max(grade)<60
Union
Select sno from s where sno not in( select sno from E)
7. 找出英語六級考試中合格人數最少的考試年份和月份(有並列的都要列出,用一句SQL語句)。
Select year , month From E
Where level = 6 and grade>=60
Group by year , month
Having count(*) <=all
(Select count(*) from E where level=6 and grade>=60 group by year , month )

我是從「上海全鼎軟體學院」畢業的————————

熱點內容
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:659
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:306
子彈演算法 發布:2024-09-20 08:41:55 瀏覽:284
手機版網易我的世界伺服器推薦 發布:2024-09-20 08:41:52 瀏覽:812
安卓x7怎麼邊打游戲邊看視頻 發布:2024-09-20 08:41:52 瀏覽:158
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:89
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:503
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:653
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:477
電腦主伺服器怎麼開機 發布:2024-09-20 07:19:07 瀏覽:728