数据类型转换

 

--cast转换

select CAST(1.23 as int)

 

sqlserver中的数据转换与子查询

 

 

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

 

sqlserver中的数据转换与子查询

 

 

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

 

sqlserver中的数据转换与子查询

 

 

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

 

sqlserver中的数据转换与子查询

 

--convert转换

select CONVERT(int,12.345)

 

sqlserver中的数据转换与子查询

 

 

 

 

 

 

子查询(嵌套查询)

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

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

 

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

sqlserver中的数据转换与子查询

 

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

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条数据为一页)

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-06-01
猜你喜欢
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2021-08-28
相关资源
相似解决方案