时间:2021-07-01 10:21:17 帮助过:4人阅读
select * from 表名 where 条件;
select * from student where id>3;
select * from subject where id<=4;
select * from student where name!=‘李凤‘;
select * from student where isdelete=0;
select * from students where id>3 and gender=0;
select * from students where id<4 or isdelete=0;
select * from students where name like ‘黄%‘;
select * from students where name like ‘黄_‘;
select * from students where name like ‘黄%‘ or name like ‘%靖%‘;
select * from students where id in(1,3,8);
select * from students where id between 3 and 8;
select * from students where id between 3 and 8 and gender=1;
select * from students where hometown is null;
select * from students where hometown is not null;
select * from students where hometown is not null and gender=0;
select count(*) from students;
select max(id) from students where gender=0;
select min(id) from students where isdelete=0;(返回的是1)
执行结果:
select sum(id) from students where gender=1;
select avg(id) from students where isdelete=0 and gender=0;
select 列1,列2,聚合... from 表名 group by 列1,列2,列3...
select gender as 性别,count(*) from students group by gender;
select hometown as 家乡,count(*) from students group by hometown;
select 列1,列2,聚合... from 表名
group by 列1,列2,列3...
having 列1,...聚合...
方案一
select count(*) from students where gender=1;
-----------------------------------
方案二:
select gender as 性别,count(*) from students group by gender having gender=1;
给count(*)起个别名叫rs,having是对分组后的结果集进行筛选,
select * from 表名 order by 列1 asc或desc,列2 asc或desc,...
select * from students where gender=1 and isdelete=0 order by id desc;
select * from students拿到原始数据,通过where筛选得到一个新的集,order by放在where后是针对新集排序
select * from subject
where isdelete=0
order by title;
select * from 表名 limit start,count
select * from students where isdelete=0 limit (n-1)*m,m
数据库mysql查询
标签:不同的 判断 淘宝 splay import sde 函数 col python