zoukankan      html  css  js  c++  java
  • 数据库 基础学习5— 数学函数

    1--数学函数
    
    select degree ,sqrt(degree) from score --开平方,平方根
    
    select price, ceiling(Price) from car -- 取大于当前小数的最小整数
    
    select price, floor(Price) from car -- 取小于当前小数的最大整数
    
    select price, round(Price,-1) from car -- 四舍五入,保留几位
    
    select ABS(-2) -- 取绝对值
    
    select RAND()*100 -- 生成随机数,默认是生成0-1之间的数
    
    2--字符串函数
    
    select LOWER('Welcome') --转小写
    select UPPER('welcome') --转大写
    select LTRIM(' hello')--压缩左边的空格
    select RTRIM('hello ')--压缩右边的空格
    select * from News
    select left(title,5) from News -- 从左侧截取字符串,截n个字符
    select right(title,5) from News --从右侧截取字符串,截n个字符
    select substring(title,3,5) from News--从某位置截取字符串,截取长度为n
    select reverse(title) from News -- 翻转字符串
    select replace(title,'中国','美国') from News --替换字符串
    select STUFF(title,4,3,'中国') from News--替换指定位置的字符串
    select LEN(' hello') -- 字符串的长度
    
    3--日期时间函数
    
    select * from student
    select year(sbirthday) from student -- 取日期时间中的年份
    select month(sbirthday) from student -- 取日期时间中的月份
    select day(sbirthday) from student -- 取日期时间中的天
    select GETDATE() --获取当前系统的时间
    select datepart(yy,sbirthday) from student--取日期时间的一部分
    
    --类型转换
    select len(cast(0.2 as varchar(50)))--cast(源数据 as 目标类型)
  • 相关阅读:
    poj 2425 AChessGame(博弈)
    poj2975 Nim 胜利的方案数
    hdu 5724 SG+状态压缩
    hdu 5274 Dylans loves tree(LCA + 线段树)
    hdu 5266 pog loves szh III(lca + 线段树)
    hdu 4031 attack 线段树区间更新
    51 nod 1188 最大公约数之和 V2
    51nod 1040 最大公约数之和(欧拉函数)
    51nod 1035:最长的循环节
    Nim游戏(组合游戏Combinatorial Games)
  • 原文地址:https://www.cnblogs.com/zyh-club/p/4655715.html
Copyright © 2011-2022 走看看