当前位置:网站首页>SQL statement exercises
SQL statement exercises
2022-06-28 15:09:00 【Guodong】
sql Sentence exercises
Have a look , You'll see !
1、 Inquire about students' course selection , The student number is required to be displayed 、 full name 、 Course no.
SELECT a.sno,a.sname,b.cno from dbo.student as a
right join dbo.sc as b on a.sno= b.sno
2、 Inquire about ‘ Law school, ’ Students' courses , Ask to list the students' names 、 The course number and grade of the course taken .
select a.sname,b.cno,b.grade from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
where sdept=' Law school, '
3、 Inquire about '' School of computer science '' Optional ‘ Database and application ’ Students' grades of the course , Ask to list the student's name 、 Course name and grade .
select a.sname,c.cname,b.grade from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
inner join dbo.course as c on b.cno= c.cno
where a.sdept=' School of computer science ' and c.cname=' Database and application '
4、 Query all repaired ‘ Military theory ’ What the students do in the course , Students' names and departments are required to be listed .( Multi table connection )
select a.sname,a.sdept from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
inner join dbo.course as c on b.cno= c.cno
where c.cname=' Military theory '
5、 Inquire about the students' courses , Including students who have taken courses and students who have not taken courses , The student number is required to be displayed 、 full name 、 Course no. .
select a.sno,a.sname,b.cno from dbo.student as a
left join dbo.sc as b on a.sno = b.sno
left join dbo.course as c on b.cno= c.cno
6、 Check which students did not choose a course , The student number is required 、 Name and department .
select a.sno,a.sname,a.sdept from dbo.student as a
left join dbo.sc as b on a.sno = b.sno
left join dbo.course as c on b.cno= c.cno
where c.cname is null
7、 Use subquery to query and ‘ Monkey D Luffy ’ Student number of students in the same department 、 full name 、 departments .
select * from dbo.student as a
where a.sname !=' Monkey D Luffy ' and a.sdept in(select b.sdept from dbo.student as b where b.sname =' Monkey D Luffy ')
8、 Use the subquery to find out that the average score is greater than 80 The student number of the student 、 full name 、 departments .
select s.sno,s.sname,s.sdept from dbo.student as s
where s.sno in (select b.sno from dbo.sc as b group by b.sno having avg(b.grade)>80 )
9、 The subquery is used to repair ‘A008’ All data of students whose grades are higher than the average of this course .
select * from dbo.student as s
inner join dbo.sc as t on s.sno = t.sno
inner join dbo.course as c on t.cno=c.cno
where t.cno='A008'
and t.grade>(select avg(v.grade) from dbo.course as t
inner join dbo.sc as v on t.cno=v.cno
where t.cno='A008')
10、 Inquire about ‘’ Medical school ‘’ The student number of the student with the highest test scores .
Law 1 :
select top 1 a.sno,max(grade) from dbo.student as a
inner join dbo.sc as b on a.sno = b.sno
where a.sdept=' Medical school '
group by a.sno
order by max(grade)desc
Law two :
select top 1 st.sno
from student st left join sc s on st.sno=s.sno where st.sdept=' Medical school '
order by s.grade desc
边栏推荐
- 一文教你快速生成MySQL数据库关系图
- 不要使用短路逻辑编写 stl sorter 多条件比较
- 论文解读(GCC)《Efficient Graph Convolution for Joint Node RepresentationLearning and Clustering》
- Leetcode (88) -- merge two ordered arrays
- Express模板引擎
- 【mysql学习笔记23】索引优化
- 笔试面试算法经典–最长回文子串
- Power battery is divided up like this
- 浪潮网络步步为赢
- Yiwen teaches you to quickly generate MySQL database diagram
猜你喜欢
![[C language] nextday problem](/img/7b/422792e07dd321e3a37c1fff55c0ca.png)
[C language] nextday problem

当下不做元宇宙,就像20年前没买房!

Mingchuangyou products passed the listing hearing: seeking dual main listing with an annual revenue of 9.1 billion

Express模板引擎

张同学还没学会当主播

The hidden crisis of Weilai: past, present and future

SAP MTS/ATO/MTO/ETO专题之九:M+M模式前后台操作,策略用50,提前准备原材料和半成品

第四大运营商,难成「鲶鱼」

如何从零搭建10万级 QPS 大流量、高并发优惠券系统

With a return of 5000 times, the South African newspaper invested in Tencent to make a province
随机推荐
老板嘱咐了三遍:低调、低调、低调
Vscode writes markdown file and generates pdf
WSUS客户端访问服务端异常报错-0x8024401f「建议收藏」
What are the benefits of this PMP certificate?
浪擎与浪潮,一个从OEM到价值共生的生态样板
【算法篇】刷了两道大厂面试题,含泪 ”重学数组“
Leetcode (88) -- merge two ordered arrays
Could you tell me whether the batch addition of Oracle such as insert all was not blocked?
云杉网络DeepFlow帮助5G核心网和电信云构建可观测性
考了这个PMP证书到底有什么好处?
C#/VB.NET 将PDF转为Excel
动力电池,是这样被“瓜分”的
High "green premium" of environmental protection products? How far is the low-carbon lifestyle from people
Not being a meta universe now is like not buying a house 20 years ago!
Le patron a donné trois ordres: discret, discret, discret
3. Caller 服务调用 - dapr
组合总和-Leetcode
PMP真的有用吗?
C语言学习-19-全排列
The latest pycharm activation cracking code in 2022 is permanent_ Detailed installation tutorial (applicable to multiple versions)