SQL面试题,工作整理sql
一、数据库和算法
表名:student,name,course,score
张青 语文 72
王华 数学72
张华 英语 81
张青 物理 67
1、用sql查询出“张”姓学生中平均成绩大于75分的学生信息;
select * from student where name like ‘张%’ having avg(score) > 75
2、work表:id,name,sex,wages(基本工资)
money表:department(部门),id,watermoney(水电费),money(奖金),rent(房租)
1)单表查询
查询某个表:select *from work
插入某个表字段:insert into work values(1010,'在','女',1000)
删除表里面的某个字段:delete from work where id='1001'
修改名字为张小虎的id号update work set id=101 where name='张小虎
查询姓名为张开头的:select * from work where name like '张%'
2)多表查询 ( GROUP BY分组)
查询黄三的工资情况:
select *from work,money where work.id=money.id and name='黄三'
查询在测试部门房租低于70的姓名
select name from work,money where work.id=money.id and department="测试部" and rent<70
3、一个表number按照num降序,去前3个排序(从大到小,asc升序)
select * from number order by num desc limit 3
4、如何一条sql语句查找表中第二大值
select min(num) from (select * from number order by num desc limit 2 ) as a
SELECT
(SELECT DISTINCT num FROM number ORDER BY num DESC LIMIT 1, 1)
AS SecondHighestNum
select * from number order by num desc limit 1,1
二、工作整理sql
1、显示全部字段,并且要默认几个字段靠前
- *,A可以随意换
2、查询某个数据库的表
数据库名.表名
3、UUID函数(后期学习)
4、更新某个订单号的,相关字段
UPDATE 数据库名.表名 SET 列名称 = 更新新值 WHERE 列名称 = 某值条件
5、删除相关
Delete from 数据库名.表名 where 条件
6、根据id号左连接
Select * from 表 a
Left join 表 b on a.id=b.id
And b.**=20 where b.**=
7、左链接,嵌套查询
8、插入表
Inset into 表()values ();
9、求和sum,求数量 count 排序 order by desc/asc
10、EXISTS 指定一个子查询,检测 行 的存在。 https://www.cnblogs.com/xuanhai/p/5810918.html
11、like用法
Like ‘%****%’
最新文章
- redis-内存异常 Redis is configured to save RDB snapshots解决
- 对datatable操作,查询
- [Eclipse] - 集成Tomcat热加载插件
- ifstat-网络接口监测工具
- Powershell 条件操作符
- bash代码
- 关于QT5使用QtScript解析QJsonArray数组的问题
- 数据库 -->; SQL Server 和 Oracle 以及 MySQL 区别
- JAVA进阶3
- 通过itools安装ipa时,如果装不上提示";Mismatche...onIdentifierEntitlement";
- POJ 2513 - Colored Sticks - [欧拉路][图的连通性][字典树]
- go语言学习--protobuf的学习
- Shell脚本 | 抓取log文件
- 【 js 算法类】这么全的数组去重,你怕不怕?
- thinkphp5.0返回插入数据id
- Java web项目中java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 修改hosts搭建本地站点
- jQuery中的append()和prepend(),after()和before()的差别
- cron定时备份数据库
- Python 错误总结