sql server基本操作语句1

select * from 表名 where 范围  --选择

where 字段 like '%value%'  --包含value的内容,查找

select * from 表名 order by 字段 desc    --排序

select sum(字段) as 新名字 from 表名   --求和

select avg(字段) as 新名字 from 表名   --求平均值

select max(字段) as 新名字  from  表名   --求最大值

select min(字段) as 新名字 from 表名  --求最小值

--增 
insert into 表名 列名 values 列值  --插入单行
insert into 已有的新表名 列名 select 原来列名 from 原表名   --将现有表数据添加到一个已有表

--删 
delete from 表名 where 删除条件   --删除满足条件的行
truncate table 表名    --将整个表删除 (删除表的所有行,但表的结构,列,约束,索引等不会被删除,不能用于有外键约束引用的表)

--改 
update 表名 set 列名=更新值 where 更新的条件

--查
select 列名 from 表名 where 查询条件表达式 order by 排序的列名  asc或者desc  --精确条件查询 
select *from 表名    --查询所有的数据行和列
select 列名1,列名二,列明三 from 表名 where 查询条件表达式    --查询部分行列(条件查询)
select 列名 as 姓名 from 表名 where 查询条件表达式    --在查询中使用 AS 更改列名
select 列名 from 表名 where 查询条件表达式 order by desc或者asc   --查询排序(先按条件查询 在进行升降排序)

--模糊查询
select * from 表名 where 列名 like%%--使用 like 进行模糊查询
select * from 表名 where 列名 between 数值 and 数值    --使用between在某个范围内进行查询
select 列名 from 表名 where 列名(address) in (‘上海’,‘山西’,‘山西’)   --使用in在列举值内进行查询

--分组查询
select 列名1 as 汉字(学员编号),AVG(列名成绩) as 汉字(平均成绩) from 表名 group by 列名1   --使用 group by 进行分组查询
select1 as 汉字,AVG(列名2as 汉字 from 表名 group by1 having count(列二)>1    --使用 having 子句进行分组筛选 (where只能在没有分组的里面使用,分组后只能使用having来限制条件)

--内连接
select1.name,表2.chengji from1,表2 where1.name=2.name   --在where子句中指定连接条件
select1.name,表2.chengji from1 inner join2 on1.name=2.name    --在from子句中使用join...on
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值