zoukankan      html  css  js  c++  java
  • SQL查询中用到的函数

    数据库表  students    

    1、平均值avg

      语法:select avg(列名)from 表名
      例:select avg(age)as age_avg from students
        as的意思是将输出的列名重定义,以as后面的文字输出
      结果:

    2、返回指定条件的行数 

      返回指定列的值的数量(null不做计算)
      如果不加列名,以*代替则返回表中的数量
      语法:select count(列名)from 表名
      
      返回指定列剔除重复数据的数量
      语法:select count(distinct 列名)from 表名
     
      例:select count(*)as students_number from students
      结果:
     
    3、返回第一条、最后一条、最大值、最小值、相加的和所在的数据
      第一条:first()
      最后一天:last()
      最大值:max()
      最小值:min()
      相加的和:sum()
     语法:select first/last/max/min/sum(age)as age_avg from students
     执行参照1、2条例子
     
    4、分组
      语法:select 列名 from 表名 where 列名=值 group by 列名
        where作为判断语句可有可无
      例:select sum(age),address from students  group by address
      结果: 
     
    5、返回文本字段中值的长度
      语法:select len(列名)from 表明
     
    6、返回当前的日期和时间
      语法:select now() from 表名
     
    7、对函数显示的字段进行格式化
      语法:select format(列名,指定显示格式)from 表名 
     
    8、将函数字段的值转化为大写
      语法:select ucase(列名)from 表名
     
    9、将函数字段的值转化为小写
      语法:select lcase(列名)from 表名   


    非学无以广才,非志无以成学 
                ——定一个小目标,每天进步一点点
  • 相关阅读:
    /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法
    device mapper的使用
    linux中挂载硬盘报错(you must specify the filesystem type)
    Linux系统分区方案建议
    正确配置Linux系统ulimit值的方法
    ulimit -c unlimited
    ulimit -n 修改
    修改Linux内核参数,减少TCP连接中的TIME-WAIT
    sysctl -P 报错解决办法
    linux 内核参数调整优化网络
  • 原文地址:https://www.cnblogs.com/insane-Mr-Li/p/9061916.html
Copyright © 2011-2022 走看看