码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver中的 数据转换 与 子查询

时间:2014-11-12 00:35:00      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   sp   

原文:sqlserver中的 数据转换 与 子查询

数据类型转换

 

--cast转换

select CAST(1.23 as int)

 

bubuko.com,布布扣

 

 

select CAST(1.2345 as decimal(18,2))

 

bubuko.com,布布扣

 

 

select CAST(123 as varchar(10))     整型转换成字符串型

 

bubuko.com,布布扣

 

 

select CAST(‘123.333‘ as decimal(18,4))    字符串型转换成浮点型

 

bubuko.com,布布扣

 

--convert转换

select CONVERT(int,12.345)

 

bubuko.com,布布扣

 

 

 

 

 

 

子查询(嵌套查询)

---查找男同志里面年龄最大的人的全部信息(top 1的意思是取排列为第一行的全部信息)

select top 1* from haha where sex=order by age desc

 

--子查询(将原来表中的数字,转换成另一个表的数据

bubuko.com,布布扣

 

---查找人数最多的部门的人中岁的人的信息(大括号内命令的意思是查询某个部门的名称)

select * from haha where bumen =(select top 1 bumen from haha group by bumen order by COUNT(*) desc)and age=35

 

子查询的应用5条数据为一页):

---查看一个表能够分成多少页

select CEILING (COUNT(*)/5.0) from haha     celing地板的意思,小数点后一位只要不是0就会进1

 

---分页代码,前面top代表一页有多少条数据,后面代码是过滤当前页面的前面页面的数据

select top 5* from haha where code not in (select top 10 code from haha)

这是显示第三页,修改页数只修改括号内的top后面的数即可(每5条数据为一页)

sqlserver中的 数据转换 与 子查询

标签:des   style   blog   http   io   color   ar   os   sp   

原文地址:http://www.cnblogs.com/lonelyxmas/p/4090865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!