Mysql常用查询

摘自:https://blog.csdn.net/weixin_41189380/article/details/83375281

Mysql常用查询

1. 单表查询

 

查询一张表:select * from table;

查询指定字段:select  c1, c2, c3 from table;

where条件查询:select c1, c2, c3 from table where id=1;(>, <, >=, <=... ...)

带in关键字:select c1, c2 from table where age in (21, 23);

带between and的范围查询:select  c1, c2 from table where age between 21 and 29;

带like的模糊查询:select c1, c2 from table where like 'Wshile'; (Wshile%, %Wshile%)

空值查询: select c1 from table where name is(not) null;

带and的多条件查询:select * from table where gname='一年级' and age=23;

带or的多条件查询:select * frome t_student where gradeName=’一年级’ or age=23;//或者,条件只要满足一个

distinct去除重复查询:select destinct c1 from table;

对查询结果order by:select * frome t_student order by age desc;//降序,从大到小,不加desc默认为升序

分组查询group by:select gradeName,count(stuName) from t_student group by gradeName;

 

 

 

2. 多表连接查询

表一:t_book

 

 表二:t_bookType

 

posted @ 2020-03-25 10:58  Wshile  阅读(218)  评论(0编辑  收藏  举报