1、
?
--数学函数;ABS(-8)绝对值、ceiling(3.12) 取上线、floor取下限、power(2,3)几次方、
--round()四舍五入
--sqrt开平方根、squar平方
?
?
--字符串函数
--ASCII 返回字符串最左边的字符ascii码
select ASCII('name')
select ASCII(name)from biao--查看所有人名的首字符的ascii码
--char 将ascii码转换成字符
select CHAR(70)
select CHAR(yuwen)from biao--讲所有语文分数转换成字符
--注意,(整数)所转换的表达式或者常量需要在0-256之间,超出的话输出n
?
--LEN 返回字符串的长度
select LEN('asdfghh')
select LEN(name)from biao --显示所有姓名的长度
?
--charindex 返回字符串首个字符出现在某个字符串从头开始为几的索引
select CHARINDEX('d','asdfghhjkkhg')--索引从1开始
select CHARINDEX('1990',birth) from studant --查看在生日里面出现的索引
?
?
--difference 返回相似度 用0——4表示相似度
select DIFFERENCE('asddfghjk','adfjkgh')
--LEFT 表示从左边截取字符串
select LEFT('asfgdsssdgh',4)
?
--RIGHT 从右边
select right('asfgdsssdgh',4)
?
--lower 全部转化成小写
select LOWER('asfasdgsgDDFQWEG')
--upper 大写
select upper('asfasdgsgDDFQWEG')
?
--Ltrim 去掉左边的空格
select LTRIM(' asd ')
--Rtrim 去掉右边的空格
select RTRIM(' asd ')
?
--patindex 相当于charindex 返回字符串所在字符中的首字符索引位
select PATINDEX('%df%','ssdfghss')
?
--Replace 查找替换
select REPLACE(sex,'女','姑娘')from biao--只显示,不更改
--replicat 复制粘贴
select REPLICATE('asd ',3)
--reverse 翻转
select REVERSE('asdfgghjk')
?
--space 空格
select 'a'+SPACE(5)+'bc'
?
--str 强制转换成字符串
select STR(123456.222,5,1)--参数1是需要转换的数值,参数2是转换之后保留的长度
--参数3是小数点后需要保留的位数
--注意,参数2在小于参数1整数部分位数时无法转换
?
--stuff
--从第几个索引的位置,看看需不需要向后删除几位,然后将需要插入的内容插入
--参数1是需要被插入的字符串
--参数2是从第几个索引开始
--参数3是是否需要向后删除几个字符
--参数4是新插入的字符
select STUFF('asddfg',3,2,'HELLO')
?
--substring?
--截取字符串
--参数1是被截取的字符串
--参数2是从哪个索引开始
--参数3是截取的长度
select SUBSTRING('asdfghjjgfddrtyy',4,5)
?
2、
?
--查询全部
select * from student
--查询李四的所有信息
select * from student where name ='李四'
--查询李四的成绩
select score from student where name = '李四'
--添加一条数据(若之前有删除数据的情况,就会放在从头开始删除数据的第一行)
insert into student values(7,'铃铛','1993-4-5','男',79)
?
--给张全蛋改名
update student set name='李狗蛋'where name ='张全蛋'
--给铃铛改性别
update student set sex ='女' where name ='铃铛'
?
--赵六转学
delete from student where name ='赵六'
?
--排序,升序
select * from student order by score
--降序
select * from student order by score desc
--只要最高分
select top 1 * from student order by score desc
--只要最低分
select top 1 * from student order by score
?
--查看所有学生姓名(利用as另起别名显示)
select name as 学生姓名 from student?
--查看所有学生的姓名和分数(另起别名)
select name as 学生姓名,score as 分数 from student
?
--查看所有姓王的学生的所有信息(模糊查询)
select * from student where name like '王%'
--查看所有1993年的学生的所有信息
select * from student where birth like '1993%'
--查看所有生日最后一天带6的学生的信息
select * from student where birth like '%6'
--查看姓名中间字为狗的学生的所有信息
select * from student where name like '%狗%'
--查看姓李的并且名字只有两个字的学生的所有信息
--下划线模糊查询,只代表一个字符(不常用)
select * from student where name like '李_'
?
?
--查看分数在80以上的学生的所有信息
select * from student where score >=80
--查看60-80之间分数的所有学生信息
select * from student where score between 60 and 80
--查看分数低于60的学生的姓名
select name as 学生姓名 from student where score <60
?
--修改分数在70-80之间的所有学生的sex=男
update student set sex ='男' where score between 70 and 80
?
--计算345678 + 789456
select 345678+789456
?
--查询所有人名 distinct 去重
s