当前位置:网站首页>面试SQL语句,学会这些就够了!!!
面试SQL语句,学会这些就够了!!!
2022-08-02 13:19:00 【InfoQ】
一、单张表

二、多表


三、根据要求写出SQL语句。
select s_score,s_id from score where c_id = 01;select s_score,s_id from score where c_id = 02;select * from (select s_score,s_id from score where c_id = 01) t1,(select s_score,s_id from score where c_id = 02) t2 where t1.s_score>t2.s_score and t1.s_id=t2.s_id //自连接select * from student where s_id in (select t1.s_id from(上面的3)) //没有查出成绩select student*,s_score_01,s_score_02 from student,(select t1.s_id,t1.s_score s_score_01,t2.score s_score_02 from(上面的3)) t3 where t3.s_id = student.s_id//where 这个条件是在group by 分组之前用的,而用group by分组之后条件需要用having select * from student,(select s_id,avg(s_score) avg_score from score group by s_id having avg_score >= 60) t1 where student.s_id = t1.s_idselect * from student left join (select s_id,avg(s_score) avg_score from score group by s_id ) t1 on student.s_id = t1.s_id where avg_score < 60 or avg_score is nullselect t_id from teacher where t_name="张三"select c_id from course where t_id = (select t_id from teacher where t_name="张三" ) //看这个老师教什么课select * from student where s_id in(select s_id from score where c_id =(select c_id from course where t_id =(select t_id from teacher where t_name="张三")))select student.s_id,student.s_name,count(score.s_id) 选课总数,sum(s_score) 总成绩 from student left join score on student.s_id = score.s_id group by score.s_idselect student.* from student,(select s_id from score where c_id=01) t1 ,(select s_id from score where c_id=02) t2 where student.s_id = t1.s_id and t1.s_id = t2.s_idselect student.* from student left join (select * from score where c_id = 01) t1 on student.s_id = t1.s_id left join (select * from score where c_id = 02) t2 on t1.s_id = t2.s_id where t1.s_score is not null and t2.s_score is null边栏推荐
- 供应磷脂-聚乙二醇-羧基,DSPE-PEG-COOH,DSPE-PEG-Acid,MW:5000
- 【C语言】函数哪些事儿,你真的get到了吗?(2)
- 如何通过DBeaver 连接 TDengine?
- 单例模式的七种写法,你都知道吗?
- 攻防世界----unfinish
- SQL Server database generation and execution of SQL scripts
- RISC-V instruction format and 6 basic integer instructions
- 你知道图论的Dijkstra吗?
- 吾爱第三课-修改版权和资源
- 86.(cesium之家)cesium叠加面接收阴影效果(gltf模型)
猜你喜欢

【C语言】剖析函数递归(1)
![PHP+MYSQL [Student Information Management System] (Minimalist Edition)](/img/86/d5d39eef0600acabbf3ac16c255c18.png)
PHP+MYSQL [Student Information Management System] (Minimalist Edition)

Win11怎么修改关机界面颜色?Win11修改关机界面颜色的方法

In-depth analysis and use of Ribbon load balancing

Object.entries()

单例模式的七种写法,你都知道吗?

php - the first of three solid foundations

RISC-V 指令格式和6种基本整数指令

k8s之KubeSphere部署有状态数据库中间件服务 mysql、redis、mongo

scrapy框架初识1
随机推荐
为什么IDEA连接mysql Unable to resolve table 编译报错但是可以运行
Seata Distributed Transaction
How to connect DBeaver TDengine?
SQL函数 USER
Enterprise Network Planning Based on Huawei eNSP
[C language] Explicit array solution (1)
The uniapp/applet onload method executes the interpretation every time the page is opened
k8s之KubeSphere部署有状态数据库中间件服务 mysql、redis、mongo
【C语言】剖析函数递归(3)
Markdown怎么加入emoji
永远退出机器学习界!
你真的懂单例模式么
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
鲁大师7月新机性能/流畅榜:性能跑分突破123万!
方正璞华“劳动人事法律自助咨询服务平台”在武汉武昌区投入使用!
【C语言】虐打循环结构练习题
Introduction to Scala Basic Syntax (3) Various Operators in Scala
基于华为eNSP的企业网络规划
嵌入式系统驱动初级【2】——字符设备驱动基础上_基础框架
How to do short video food from the media?5 steps to teach you to get started quickly