当前位置:网站首页>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
边栏推荐
- 不要使用短路逻辑编写 stl sorter 多条件比较
- 石油化工行业供应链系统驱动管理模式创新升级,强化企业内部管理
- Summary of technical difficulties of wearable neural signal and behavior data detection and recording system for birds in flight
- 力扣今日题-522. 最长特殊序列
- With a return of 5000 times, the South African newspaper invested in Tencent to make a province
- 张同学还没学会当主播
- Leetcode (406) - rebuild the queue based on height
- [JS] Fibonacci sequence implementation (recursion and loop)
- 【mysql学习笔记23】索引优化
- QQ被盗号后群发黄图,大批用户“社死”
猜你喜欢

成龙和快品牌,谁才是快手的救星?

教育行业SaaS应用管理平台解决方案:助力企业实现经营、管理一体化

With a return of 5000 times, the South African newspaper invested in Tencent to make a province

美国乔布斯,殁了;中国乔布斯,卖了

猫狗图像数据集上的深度学习模型性能对比

Not being a meta universe now is like not buying a house 20 years ago!
ORACLE中dbms_output.put_line输出问题的解决过程

【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境

Halcon basic summary (I) cutting pictures and rotating images
![[C language] nextday problem](/img/7b/422792e07dd321e3a37c1fff55c0ca.png)
[C language] nextday problem
随机推荐
MIPS汇编语言学习-01-两数求和以及环境配置、如何运行
使用LamdbaUpdateWrapper的setSql作用及风险
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和数据表格横向组合起来形成最终结果图
成龙和快品牌,谁才是快手的救星?
How to solve the following problems in the Seata database?
R language ggplot2 visualization: use the patchwork package to horizontally form two ggplot2 visualization results into a new result visualization combination diagram (using the | symbol)
技术弄潮儿
Leetcode (406) - rebuild the queue based on height
The hidden crisis of Weilai: past, present and future
JS judge whether the string is empty or not
云杉网络DeepFlow帮助5G核心网和电信云构建可观测性
买卖股票的最佳时机
New offline retail stores take off against the trend, and consumption enthusiasm under the dark cloud of inflation
Combined sum leetcode
3. Caller 服务调用 - dapr
PMP认证证书的续证费用是多少?
ROS21讲
从莫高窟到太平洋,海量数据找到了新家园
sql语句 练习题
What is the renewal fee for PMP certificate?