一、数据库和算法

 

表名: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、显示全部字段,并且要默认几个字段靠前

  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 ‘%****%’

 

 

最新文章

  1. redis-内存异常 Redis is configured to save RDB snapshots解决
  2. 对datatable操作,查询
  3. [Eclipse] - 集成Tomcat热加载插件
  4. ifstat-网络接口监测工具
  5. Powershell 条件操作符
  6. bash代码
  7. 关于QT5使用QtScript解析QJsonArray数组的问题
  8. 数据库 --&gt; SQL Server 和 Oracle 以及 MySQL 区别
  9. JAVA进阶3
  10. 通过itools安装ipa时,如果装不上提示&quot;Mismatche...onIdentifierEntitlement&quot;
  11. POJ 2513 - Colored Sticks - [欧拉路][图的连通性][字典树]
  12. go语言学习--protobuf的学习
  13. Shell脚本 | 抓取log文件
  14. 【 js 算法类】这么全的数组去重,你怕不怕?
  15. thinkphp5.0返回插入数据id
  16. Java web项目中java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  17. 修改hosts搭建本地站点
  18. jQuery中的append()和prepend(),after()和before()的差别
  19. cron定时备份数据库
  20. Python 错误总结

热门文章

  1. Vue13 样式动态绑定
  2. vscode安装教程(含插件配置)
  3. 树莓派读取ip
  4. 了解舵机以及MG996R的控制方法
  5. Json.stringfiy json未定义
  6. 路飞项目使用mysql数据库详细讲解
  7. asp多模块功能代码,单调用插入的case方法
  8. 子路由path路径带 ‘/‘与不带
  9. Mogeaver 连接数据库
  10. ESXi 安装 Truenas Core 解决企业共享存储免费方案