zoukankan      html  css  js  c++  java
  • mysql的distinct,count,in 和 offset 使用

    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; #跳过前两行

    # 欢迎交流

  • 相关阅读:
    Guava入门第四章(Objects)
    Guava入门第三章(Preconditions)
    Guava入门第二章(Splitter)
    Guava入门第一章(Joiner)
    Docker入门第六章
    Docker遇到的问题
    Docker命令图
    2016-08-26-Java比较器的使用
    2017-10-6-MyBatis配置简述
    2017-9-17-Java Exception小结
  • 原文地址:https://www.cnblogs.com/qi-yuan-008/p/12198839.html
Copyright © 2011-2022 走看看