zoukankan      html  css  js  c++  java
  • sql语句

    平时的数据库操作都是图形化界面完成了。然而有时候批量操作字段的时候还是不得不用到原生的sql语句。so这个就专门记录下自己使用过的又记不住的sql语句。没事看看拿起来当备忘录

      批量修改某个字段的数据

      update 表名 set 字段名=" " where 条件;

      update order set is_finish='2' where is_finish = '1'.   (别order表中is_finish=2的都改为1)

      时间查询:    

          ps:date为表中时间字段的字段名

      查询近七天的数据:

        select * from 表名 where datediff(now(), date) < 7;

      查询七天以外的数据:

        select * from 表名 where datediff(now(), date) > 7;

      查询本月的数据:

        select * from 表名 where date_format(date, "%Y%m") = date_format(Now(),"%Y%m");

      查询某个月的数据:

        select * from 表名 where date_format(date, "%Y%m") = date_format("2018-12-12","%Y%m");

       FROM_UNIXTIME(unix_timestamp,format)

       参数unix_timestamp  时间戳 可以用数据库里的存储时间数据的字段

       参数format  要转化的格式  比如“”%Y-%m-%d“”  这样格式化之后的时间就是 2017-11-30

        select update_time,from_unixtime(update_time,'%Y-%m-%d') as riqi FROM iot_manageruser;

      链表查询:

      select * 表一 as a left join 表二 as b on a.外键 = b.主键

      select * mangeruser as m left join company as c on m.company_id = c.id;

  • 相关阅读:
    学习Bitmap,处理“海量”数据
    学习Trie树,处理“海量”数据
    学习KMP算法
    学习堆与栈内存分配方式
    学习继承和虚析构函数
    学习处理数组子集和的算法
    学习类中的const和static类型
    学习利用动态规划解决若干问题
    【MySQL】MySQL忘记root密码解决方案
    【API】短信通106端口验证短信的实现
  • 原文地址:https://www.cnblogs.com/ppzhang/p/10072533.html
Copyright © 2011-2022 走看看