zoukankan      html  css  js  c++  java
  • sqlserver中的数据转换与子查询

    数据类型转换

     

    --cast转换

    select CAST(1.23 as int)

     

     

     

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

     

     

     

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

     

     

     

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

     

     

    --convert转换

    select CONVERT(int,12.345)

     

     

     

     

     

     

     

    子查询(嵌套查询)

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

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

     

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

     

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

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

  • 相关阅读:
    protobuf 使用
    rsync实现Linux与windows增量更新数据
    单例模式-通用写法1
    cxf RESTful service client
    IDEAspringboot项目自动生成junit测试
    Centos8配置网络NM
    Oracle终止正在执行中的存储过程
    Mysql Statement violates GTID consistency: CREATE TABLE ... SELECT.
    shell中判断变量是否存在某个集合中
    redis-ha部署
  • 原文地址:https://www.cnblogs.com/hqjy/p/4077371.html
Copyright © 2011-2022 走看看