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;

posted @ 2018-12-05 18:17  X小白的逆袭之旅  阅读(200)  评论(0编辑  收藏  举报