Delete from 表名 where 列名 = ‘’
删除
Update 表名 set 列名= ‘’ where 列名 = ‘’
改动
Update car ser price=price*0.9 where price >30
查询
Select * from 表名 全部列
Select 列名1,列名2 from 表名 投影
Select * from 表名 where 条件 筛选
-
等值与不等值
Select * from car where code= ‘c001’
Select * from var where code != ‘c001’
Select * from car where code in (‘c001’,’c003’)
-
模糊查
Select * from car where name like ‘宝马%’ %为任意多个任意字符
Select * from car where name like ‘__5%’第三个字母是5 下划线代表的是一个任意字符
Select * from car where name like ‘%5%’ 包括5的
-
排序
Select * from 表名 where... Order by 列名(ASC/DESC) 升序或降序 列名(ASC/DESC)
Select *from car oeder by brand asc , price desc...
统计查询:
聚合函数
Select sum (price<列名>) from car . = 查询所有的价格之和 sum() 求和
Select count (*) from car where class="95031" . = 统计数据的条数
Select max (code) from car = 求最大值
Select min (price) from car = 求最小值
Select avg (price) from car = 求平均值
分页查询
每页显示5条数据,取第n页的数据
Select * from car limit (n-1)*5,5 第一个数字是跳过几条数据,第二个数字是取几条数据。
去重查询
Select distinct 列名 from car 去掉重复的关键字
分组查询
Select count (*) , brand from car group by brand select brand from car group by brand having count (*)>3
分组之后根据条件查询使用having 不使用where
连接查询 对列的扩展
Select * from info join nation on info.nation = nation code
Select * from info ,nation
联合查询 对行的扩展
Select code,name from info
union
Select code,name from nation
子查询
-
无关子查询
外层查询(里层查询)
子查询的结果当作父查询的条件
子查询:Select code from nation where name= ‘汉族’
父查询:select * from info where nation = ‘(子查询)’
-
相关子查询
查询汽车表中油耗低于该系列平均油耗的所有汽车信息。
子查询:Select * from car where oil <(该系列平均油耗)
父查询:Select avg (oil) from car where brand = ‘某个系列’
Select * from car a where oil <(select avg (oil) from car b where b.brand= ‘a.brand’)