zoukankan      html  css  js  c++  java
  • 5select的运用

    四、select的运用

    --汇总函数 max()最大值,min()最小值,avg()平均值
    select max(age),min(age),avg(age) from tablename; --算出表中age的最大值,并非全部max(age)数据
    select max(age),min(age),avg(age) from tablename where id!=1;

    select * from tablename where max(age); --错误


    --子查询 返回的是最大值
    select *from tablename where age in(select max(age) from tablename);
    select max(age)from tablename where age in(select max(age) from tablename);


    --查询最小值到最大值之间的全部数据
    select* from malestaff where age
    between (select MIN(age) from malestaff) and (select MAX(age) from malestaff);

    select count(*) form tablename --统计人数


    --分组 根据id的不同进行分组

    select * from tablename group by id;


    --排序 根据id的不同进行排序,默认为升序,desc代表降序
    select * from tablename order by id;
    select * from tablename order by id desc;


    --多种条件约束
    select * from tablename
    where age is not null --查询条件
    group by age --分组字段 where意义等同于having
    having count(*)>2 --分组条件 即相同age的人数〉2
    order by count(*); --根据人数的不同,对查询数据进行升序

  • 相关阅读:
    1245. Tree Diameter
    771. Jewels and Stones
    830. Positions of Large Groups
    648. Replace Words
    647. Palindromic Substrings
    435. Non-overlapping Intervals
    646. Maximum Length of Pair Chain
    645. Set Mismatch
    242. Valid Anagram
    438. Find All Anagrams in a String
  • 原文地址:https://www.cnblogs.com/gd-luojialin/p/8506749.html
Copyright © 2011-2022 走看看