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;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值