您的位置:首页 > 数据库

SQL 的简单命令(增删改查)

2016-11-28 11:14 330 查看
数据库操作的资料: 链接: https://pan.baidu.com/s/1dFl3q6X 密码: nvy7

-- 增:insert into 表名 (列名) values (值)
insert into Test (id,name) values (7,'dew')

-- 删:表名 where 列名=值
delete Test where id=3

-- 查:select 列名 from 表名 where 列名=值
select id from Test

-- 查询所有信息:select * from 表名
select * from Test

-- 使用别名查询之一:select 列名 as 别名 from 表名
select id as ab from Test

-- 使用别名查询之二:select 表的别名.列名 as 列的别名 from 表名 表的别名
select a.name as goodName from Test a

-- 区间查询:select * from 表名 where 列名 Between 值 and 值
select * from Test where id Between 3 and 5

-- 指定查询:select * from 表名 where 列名 in(指定的值,指定的值,指定的值)
select * from Test where id in(3,5,6)

-- 模糊查询:select * from 表名 where 列名 like 含有的字符(_代表一个占位符,%表示任意字符)
select * from Test where name like '_a%'

-- 去重复查询:select  distinct 列名,列名 from 表名
select  distinct id ,name from Test

-- 降序:select * from 表名 order by 列名 desc
select * from Test order by id desc

-- 升序:select * from 表名 order by 列名 asc
select * from Test order by id asc

-- 改:update 表名 set 列名=新值 where 列名=值
update Test set id=5 where id=2

-- 拼接用||(比较少用)
select 'id'|| 'name' from Test


-- 查找两个表中ID相等的
select a.id, a.name,b.math from stu a,scores b where a.id = b.id

-- 右外连接
select b.id, a.name,b.math from stu a,scores b where a.id(+) = b.id
select b.id, a.name,b.math from stu a right outer join scores b on a.id = b.id

-- 左外连接
select a.id, a.name,b.math from stu a,scores b where a.id = b.id(+)
select a.id, a.name,b.math from stu a left outer join scores b on a.id = b.id

-- 满外连接
select a.id,b.id, a.name,b.math from stu a full outer join scores b on a.id = b.id

-- 最大值
select max(scores.math) from scores

-- 最小值
select min(scores.math) from scores

-- 平均值
select avg(scores.math) from scores

-- 和
select sum(scores.math) from scores

-- 列数
select count(scores.math) from scores

-- 标准差
select stddev(scores.math) from scores

-- 分组函数
select math from scores group by math
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: