当前位置:网站首页>面试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_id
select * 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 null
select 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_na
me="张三")))
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_id
select 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_id
select 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
边栏推荐
猜你喜欢
汉源高科千兆12光12电管理型工业以太网交换机 12千兆光12千兆电口宽温环网交换机
图文短视频自媒体怎么创作?如何让点击量达到10W?
你知道图论的spfa吗?
Get out of the machine learning world forever!
移动端适配,华为浏览器底色无法正常显示
基于 WeihanLi.Npoi 实现excel导入时纯汉字的日期转换
3 ways for OpenFeign to set headers
Enterprise Network Planning Based on Huawei eNSP
【C语言】手撕循环结构 ——do...while语句及循环练习题(1)
How to do short video food from the media?5 steps to teach you to get started quickly
随机推荐
k8s之KubeSphere部署有状态数据库中间件服务 mysql、redis、mongo
永远退出机器学习界!
路由-Tab切换页面
[C language] Analysis of function recursion (1)
动态组件-component
How to do short video food from the media?5 steps to teach you to get started quickly
Wireless vibrating wire acquisition instrument remote modification method
RestTemplate 使用:设置请求头、请求体
【C语言】手撕循环结构 ——do...while语句及循环练习题(1)
WPF效果第一百九十三篇之登录实现
移动端适配,华为浏览器底色无法正常显示
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
wx-wow(微信小程序动效库)
selenium chrome driver运行时的cannot determine loading status from target frame detached问题
How to turn off hardware acceleration [easy to understand]
图论之Prim,最小生成树该怎么解?
Selenium本地打开远程浏览器
Do you know Dijkstra of graph theory?
【C语言】剖析函数递归(2)
[C language] Analysis of function recursion (2)