Mysql数据库,查询,子查询,分页,分组后求和


 #只显示in里面的两条数据
select * from t11 where id in(2,10);

#从哪里到哪里的数据 范围查询
select * from t11 where id between 1 and 10;


#查询匹配字符的记录
select * from t11 where location like '%a%';
select * from t11 where location like 'a%b';

#两个下滑线
select * from t11 where location like 'd__';

# and和or   and优先被判断
select * from t11 where location like 'd__' and id=2;
select * from t11 where location like 'd__' or id=2;
select * from t11 where location like 'd__' or id=2 and age=20;

#not查询
select * from t11 where  id=2 and location not like 'a__' ;

insert into t11 select * from t11;
#查询结果不重复
select distinct id from t11;

#查询结果排序
select * from t11 order by age asc;//升序
select * from t11 order by age desc;//降序

#查询结果多字段排序   分组排序
select * from t11 order by age,uName asc;

#分组查询
select age,count(1) as total from t11 group by age;

#HAVING 分组后统计数据选择条件
select age,count(1) as total from t11 where 1=1  group by age having count(1)>1;

#在group by 后求和
select age,count(1) as total from t11 group by age with ROLLUP;

#多字段分组
select uName,age from t11   group by uName,age;

#限制查询结果行数量
select * from t11 limit 2;
select * from t11 limit 2,1;
发布了25 篇原创文章 · 获赞 0 · 访问量 501

猜你喜欢

转载自blog.csdn.net/luojiawen208/article/details/105033800
今日推荐