数据查询语句

一、数据查询语句:DQL

  作用:查询

二、DQL

  #基本查询(可不加where 条件)

  select * from 表名 where 条件;

  select 列1,列2 from 表名 where 条件;

  #过滤掉重复列

  select distinct 列1 from 表名;

  #合并为一行

  select concat (列1,列2) from 表名;

  select concat_ws ('==',列1,列2) from 表名;

  #改名

  slect 列1 as 别名,列名2 as 别名2 from 表名;

  #模糊查询(%匹配所有,_匹配一个)

  select 列名 from 表名 where 列名 like '%xx_';

  #聚合函数

  #表中记录的条数

  select count(*) from 表名;

  #查询此列的和

  select sum(列名) from 表名;

  #查询此列的平均值

  select avg(列名) from 表名;

  #查询此列的最大值

  select max(列名) from 表名;

  #查询此列的最小值

  select min(列名) from 表名;

  #分组查询

  

猜你喜欢

转载自www.cnblogs.com/badbadboyyx/p/12189132.html