首页 > 数据库技术 > 详细

mysql的distinct,count,in 和 offset 使用

时间:2020-01-15 22:22:57      阅读:74      评论:0      收藏:0      [点我收藏+]

1. distinct:去重

# distinct
select distinct name_adress from my_test_copy;   # 得到去重字段
select count(distinct name_adress) as distinct_rows from my_test_copy; #对某一列去重后统计
select distinct id, name_adress from my_test_copy;   # 得到去重字段,但是此时同时作用于两个字段,也就是只要有一个不一样就行,同时一样的才不会取出来

# select id, distinct name_adress from my_test_copy; # 不能这样写,因为distinct要放在开头

2 count:统计

# count
select count(*) as num_rows from my_test_copy;   # as:重命名
select count(1) from my_test_copy;               # 统计记录数,包括NULL值记录

3. in:判断属于特性

# in 和 not in
select * from my_test_copy where name_adress in (北京,南京);  #枚举需要的列
select * from my_test_copy where name_adress not in (北京,南京);  #枚举不需要的列

4. offset:偏置量,表示跳过多少行

select * from my_test_copy limit 2 offset 2; #跳过前两行

 

# 欢迎交流

mysql的distinct,count,in 和 offset 使用

原文:https://www.cnblogs.com/qi-yuan-008/p/12198839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!