




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
select * from student;-显示字符串的方式select 1;select a;select 12345;select DISTINCT * from studentwhere name liujiayu;where age between 20 and 30;-聚合函数select count(*) as num from student;select count(*) from student;select max(age) as MaxOfAge from student;select min(age) as MinOfAge from student;select avg(age) as AvgOfAge from student;-字符串函数-ASCII(expr):返回expr的最左端的字符的ascii码值,如果expr是纯数字,如,则可以写成ascii(),但如果不是纯数字,如a1234,则必须加引号,如ascii(a1234);select ascii(1);select ascii(a1);-CHAR(expr):将ascii码转换成字符,如果不存在ascii码为expr的字符,则返回null;select char(97);select lower(WERTsdfghETcvb);select upper(WERTsdfghETcvb);-STR(expr,length,decimal):把数值型数据转换为字符型数据。length 指定返回的字符串的长度,decimal 指定返回的小数位数。如果没有指定长度,缺省的length 值为,decimal 缺省值为。当length 或者decimal 为负值时,返回NULL; 当length 小于小数点左边(包括符号位)的位数时,返回length 个*; 先服从length ,再取decimal ; 当返回的字符串位数小于length ,左边补足空格。select str(1234.5678,6,3);-去空格select ltrim( tyu );select ltrim( tyu );-取子字符select left(123456789,2);select right(123456789,3);select substring(123456789,3,2);-寻找字符串,返回字符串中某个指定的子串出现的开始位置。-其中substring _expression 是所要查找的字符表达式,expression 可为字符串也可为列名表达式。如果没有发现子串,则返回值。-此函数不能用于TEXT 和IMAGE 数据类型。select charindex(45,45fgf123456789);select charindex(45,45fgf123456789,2);-其中子串表达式前后必须有百分号“%”否则返回值为。-与CHARINDEX 函数不同的是,PATINDEX函数的子串中可以使用通配符,且此函数可用于CHAR、VARCHAR 和TEXT 数据类型。select patindex(%4_%,fgf123456789);-重复一个指定次数的字符串。select replicate(1234,2);-字符串逆置select reverse(12345167890);-替换字符串select replace(12345167890,1,liujiayu);-返回一个有指定长度的空白字符串。select space(3);select replace(space(3), ,a);-用另一子串替换字符串指定位置、长度的子串。-STUFF (,)select stuff(1234567890,2,6,aaaa);-转换格式/*CAST(expression AS data_type)CONVERT(data_type,expression,style)convert一般在时间类型(datetime,smalldatetime)与字符串类型*/select CAST(123 as char(10);select CAST(123 as int);SELECT CAST(123.4 AS decimal(5,2);Select CONVERT(varchar(30),getdate(),101);/* 1 101 mm/dd/yy102 yy-mm-dd103 dd/mm/yy104 dd-mm-yy105 dd-mm-yy106 dd mon yy107 mon dd,yy108 hh:mm:ssor 109 mon dd yyyy hh:mi:ss:mmmmAM(或PM)110 mm-dd-yy111 yy/mm/dd112 yymmddor 113 dd mon yyyy hh:mi:ss:mmm(24小时制)114 hh:mi:ss:mmm(24小时制)or 120 yyyy-mm-dd hh:mi:ss(24小时制) 21 or 121 yyyy-mm-dd hh:mi:ss:mmm(24小时制)*/-时间日期函数select getdate();-向后算,比如后天十几号select dateadd(day,2,getdate();select dateadd(day,-10,getdate();-计算差距select datediff(day,2004-09-01,2004-09-18)select datepart(day,getdate()select datepart(month,getdate()select datepart(year,getdate()select datepart(hour,getdate()select datepart(minute,getdate()select datepart(second,getdate()-数学函数select ceiling(56.57);-返回不小于n的最小整数select floor(56.57);-返回不大于n的最大整数select round(56.5776456,3);-:四舍五入,参数为小数的位数select rand();-随机生成0,1之间的float类型值select sign(56.57);-当expr为整数、负数时分别返回、-1select sqrt(65);-返回expr的平方根select abs(-345);-返回expr的绝对
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论