赞
踩
在保证需操作的数据库中已经存在XSKC模式下的数据表student、course、sc
UPDATE XSKC.student
SET sname = ‘李勇’
WHERE sdept=‘CS’ AND sname=‘李咏’
UPDATE XSKC.student
SET sname=‘王丹丹’,ssex=‘女’,sage=20,sdept=‘MA’
WHERE sno=‘200515010’
UPDATE XSKC.COURSE
SET ccredit=3
WHERE cname=‘数据处理’
UPDATE XSKC.sc
SET grade=grade+5
WHERE cno=1
DELETE FROM XSKC.student
WHERE sdept IS NULL
DELETE
FROM XSKC.course
WHERE ccredit<1
USE student
SELECT *
FROM XSKC.student
WHERE sname like ‘王__’
USE student
SELECT sno,sname
FROM XSKC.student
WHERE sage<2019-1986
USE student
SELECT sno,sname
FROM XSKC.student
WHERE sdept IS NULL
USE student
SELECT *
FROM XSKC.sc
WHERE grade BETWEEN 70 AND 80
ORDER BY cno DESC,grade DESC
USE student
SELECT 院系=
case
when sdept=‘CS’ then ‘计算机系’
when sdept=‘IS’ then ‘信息系’
when sdept=‘MA’ then ‘数学系’
when sdept=‘EN’ then ‘外语系’
when sdept=‘CM’ then ‘中医系’
when sdept=‘WM’ then ‘西医系’
else ‘院系不明’
end,sno as ‘学号’,sname as ‘姓名’,ssex as ‘性别’,sage as ‘年龄’
FROM XSKC.student
ORDER BY 院系 DESC
USE student
SELECT sno
FROM XSKC.sc
WHERE cno=1 AND sno in(SELECT sno FROM XSKC.sc WHERE Cno=2)
USE student
SELECT distinct sdept,院系规模=
case
when count()>5 then ‘规模较大’
when count()between 4 and 5 then ‘规模一般’
when count(*)between 2 and 4 then ‘规模较小’
end
FROM XSKC.student
WHERE sdept IS NOT NULL
GROUP BY sdept
USE student
SELECT 学生总人数=COUNT(distinct sno),平均年龄=AVG(sage)
FROM XSKC.student
USE student
SELECT DISTINCT 学号=sno,选课数=COUNT(cno)
FROM XSKC.sc
GROUP BY sno
HAVING COUNT(cno)>3
USE student
SELECT sno 学号,sname 姓名,ssex 性别,sage 年龄
FROM XSKC.student
SELECT distinct IS系的学生个数=COUNT(*)
FROM XSKC.student
WHERE sdept=‘IS’
USE student
SELECT a.*
INTO ceshi
FROM XSKC.student a
WHERE sno IN
(SELECT top 2 sno
FROM XSKC.student
WHERE sdept=a.sdept
order by sno)
USE student
SELECT sno 学号,AVG(grade) 平均成绩
FROM XSKC.sc
GROUP BY sno
HAVING AVG(grade)>(SELECT AVG(grade)from XSKC.sc,XSKC.student where sname=‘赵菁菁’)
命令方式:在【SQL Server Management Studio】窗口左上方选择【新建查询】按钮,启动SQL编辑器窗口,在光标处输入T-SQL语句,单击【执行】按钮。例如第一题可输入:
select * from student where sname not like ‘刘%’
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。