zoukankan      html  css  js  c++  java
  • 【3-13】数据库函数及表连接

    一、数学函数

    (1)取上限  ceiling(值)

    例:select ceiling(oil) from car

    (2)取下限 floor(值)

    例:select floor(oil) from car

    (3)四舍五入 round(值,精确位数)

    例:select round(oil,1) from car

    (4)取绝对值 abs(值)

    例:select abs(-10) 

    (5)圆周率 pi()

    二、字符串函数

    (1)大写  upper(值)

    例:select upper(name)from car

    (2)小写 lower(值)

    例:select lower(name)from car

    (3)前删除  LTRIM(值)

    例:select     LTRIM(‘          aaa’)

    (4)后删除 RTRIM(值)

    例:select    RTRIM(‘aaa          ’)

    (5) 替换   replace(字符串,要替换值, 替换成的值)

    例:select replace(‘    asd   gr   ’,‘ ’,‘’)

    (6)截取 substring (字符串,索引,个数)

    注:索引从1开始

    例:select  substring ('hjkldsa',2,3)

    (7)左截取 left(字符串,个数)

    例:select left('cfasd',3)

    (8)右截取  right(字符串,个数)

    例:select right(‘dfsdf’,4)

    (9)长度 Len
    三、转换函数

    (1)convert(数据类型,列名)

    (2)cast(列名 as 数据类型)

    四、时间日期型

    (1)获取时间日期 getdate()

    例:select getdate()

    (2)获取年 year(日期)

    例:select year(getdate())

    (3)获取月 month(日期)

    (4)获取日 day(日期)

    (5)判断日期是否正确  isdate(日期)

    例:select isdate('2011-09-32')   返回bit 型

    (6)日期累加 dateadd(年、月、日,加的数,日期)

    例:select dateadd(day,3,'2011-09-01')

    (7)获取日期天数 datename(获取的变量,日期)

    获取变量:weekday 星期几;week 一年中第几周;day 一月中第几天;dayofyear 一年中第几天

    五、表连接

    (1)select 列名1,列名2 from 表名1,表名2 where 表名1.主键=表名2.主键

    例:select Sname,degree from student,score where student.scode=score.scode

    (2) 多子查询叠加 select 列名1,(select 列名2 from 表名2)from 表名1

    (3)select 列名1,列名2from表名1join表名2on条件

    例:select sname,degree from student join score on student.scode=score.scode

  • 相关阅读:
    【古曲】流水-古琴曲
    【文献阅读】基于特征的非局部均值图像去噪算法研究毕业论文
    【名言】后生看经书,须着看注疏及先儒解释,不然,执己见议论,恐入自是之域,便轻视古人。
    马氏距离(Mahalanobis distance)
    广义高斯分布(GGD)
    Lenna图-莱娜·瑟德贝里
    【机器学习】WIFI室内定位
    【matlab】生成列是0-255渐变的图像
    少笔画生僻字
    Gabor变换、Gabor滤波器
  • 原文地址:https://www.cnblogs.com/hclyz/p/6543689.html
Copyright © 2011-2022 走看看