zoukankan      html  css  js  c++  java
  • MySQL----示例知识点整理

    示例语句:

     select count(0),hour(c.created_at) from `behavior_client_view` c join `behavior_share` s
     on c.share_uuid=s.uuid
     where s.agent_uuid=(select uuid from user where mobile='12606666333' and deleted=0)
     and DATE_FORMAT(c.created_at,'%Y-%m') >DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')
     group by hour(c.created_at) order by hour(c.created_at);#近12个月时段统计分布

    涉及到的MySQL知识点汇总:

    1、date_format(date,format):函数根据format字符串格式化date值。

    示例:select DATE_FORMAT(now(),'%Y-%m');

       查询结果:2019-01

    2、date_sub(date,interval exp type):函数从日期减去指定的时间间隔。

      说明:date:参数是合法的日期表达式

         expr;参数是您希望添加的时间间隔

         type:参数值为:microsecond、second、minute、hour、dayweekmonthquarteryearseconde_microsecondminute_microsecondhour_microsecondhour_secondhour_minuteday_microsecondday_secondday_minuteday_houryear_month

    示例:

      select date_sub(now(),interval 2 month);  #查询:根据当前的时间减去2个月,计算得出的时间值

      查询结果:2018-11-07 11:37:48

    3、curdate():函数返回当前的日期

    示例:select curdate();

      查询结果:2019-01-07

    扩展常用函数:

    4、curtime():返回当前的时间

      查询结果:11:37:48

    最后:简单示例一条,select if(curdate()="2019-01-07",(select DATE_FORMAT(now(),'%Y-%m-%d')),1) as d;

    5、/*获取当前系统时间:年月日 时分*/

      select DATE_FORMAT(now(),'%Y-%m-%d %h:%m');  

      查询结果:2019-01-22 02:01

  • 相关阅读:
    WSS3.0安装后,系统资源消耗这么大
    通过名称找到控件(VB.NET)
    zencart 对首页静态化处理
    zen cart 模板类 template_fun class
    现在网络上流行的病毒都太“厚道”了
    从SPS2003的邮件设置上看微软标准与国际标准
    我也有了BLOG,欢迎交流
    如何给WEBPART中增加客户端代码
    如何修改More Information 中的Page 2,Page 3,Page4
    汽车保养项目[转载]
  • 原文地址:https://www.cnblogs.com/syw20170419/p/10232566.html
Copyright © 2011-2022 走看看