MySQL-------单表查询 Linux命令 2018/7/4 17:58

一、查询

库的查询:show databases;

表的查询:show tables;

字段的查询:desc 表名;

二、单表的查询

普通查询:

    查询所有列的数据 :select * from 表名;

    

    查看多列的数据: select 字段1,字段2 from 表名;

    

    查询去重后显示的单列:select distinct 字段 from 表名;

    

条件查询:where过滤后再查询

  • select * from 表名 where 条件;
  • 比较运算符(> < = ......)和逻辑运算符(and or)

    • 模糊查询:select * from 表名 where 有like的条件-----条件中有_任意单个字符和%0个或多个字符

    • 范围查找:连续between and    不连续in


    • 空判断查找:is null    is not null


聚合查询:函数--select 函数 from 表名 ;

  • count(列名)  某一列的总行数===count(*)
  • sum(数字列名)
  • avg(数字列名)  平均值
  • max(列名) 汉字也可以
  • min(列名)

分组:group by----select *或者聚合函数 from 表名 group by 字段 having 分组后的某一组的条件;


排序:order by 字段1 顺序,字段2 顺序;   asc正序   desc 倒序


限制集:select * from 表名 limit 开始索引,个数;




猜你喜欢

转载自blog.csdn.net/l_womeiyoumingzi/article/details/80916599