zoukankan      html  css  js  c++  java
  • mysql 复杂的查询语句,工作中用到的记录下

    1  去重查询

    select distinct id from user_info where xxxxxx

    2 group by 分组查询中排序

    group by本身没有排序功能,这可能是mysql不完美的地方,但是我们可以这样做

    select attack_id, time from (select * from attack_log where (time+172800) < unix_timestamp(now()) order by time desc) attack_log group by attack_id

    *注:先通过排序行成一个集合,然后再去改集合中去查,这样分组就实现了排序查询

    3 查找符合要求的 前两个数据

     select attack_id,time from attack_log a where (select count(*) from attack_log where attack_id = a.attack_id and time > a.time) <2

    *注:where 后面 其实是一个bool值。通过bool值来过滤 符合要求的数据

    mysql数据库迁移(两部曲)

    1   mysqldump -uroot -p SCBdb >> /home/zhangchuan/SCBdb.sql(将需要迁移的数据库生成sql文件)

    2   在mysql环境下 source ./SCBdb.sql;(在目标数据库的mysql环境下执行该语句)

    就这么简单

  • 相关阅读:
    Kafka学习笔记(五、Kafka偏移量)
    web-备份是个好习惯
    web-Web5
    web-web4
    web-flag就在index里
    C++日期类、时间类、日期时间类的设计
    蒙提霍尔问题简单粗暴的理解掉
    sql分组操作符与聚集函数
    sql增删改
    sql简单查询
  • 原文地址:https://www.cnblogs.com/wanghuaijun/p/5786226.html
Copyright © 2011-2022 走看看