zoukankan      html  css  js  c++  java
  • sql语句截取字符串

    Postgresql 当中有四种方式获取当前时间。
     一:now()
         通过now()获取的时间是最完整的时间,包括时区,秒也保留到了6位小数。
         select now();
         得到的结果如下
         '2014-12-24 09:28:31.545145+08'

     二:current_timestamp效果是和now()一样的。

     三:current_time 
          只显示当前的时间,不包括日期
          select current_time;
          得到的结果如下
          '09:32:02.039705+08'

     四:current_date
           只显示当前的日期,不包括小时等信息
           select current_date;
           得到的结果如下
           '2014-12-24'

     我们还可以控制now()的返回格式,如下
      select now()::timestamp(0)without time zone;(current_timestamp 是和now()一样的)
     
     时间的计算方式,如下
     select now() + interval '10 min/year/month/day/hour/sec/ (1 year 1 month 1 day 1 hour 1 min 1 sec)' 

    2.时间的计算
    --使用interval
    select now()+interval '2 day'; --2012-05-14 20:05:32.796+08 2天后
    select now()-interval '2 day'; --2012-05-10 20:07:23.265+08 2天前
    select now()+interval '2 hour'; --2012-05-12 22:06:38.375+08 2小时后 

    case when left(t5.name,2)='20' then substring(t5.name,9,2) else substring(t5.name,7,2) end GD

    截取前1~10位数字 ac17072408

     select substring(name,0,11) from profin_application;

    name=ac1707240801

     
    select substring(name,0,11) from profin_application;
    select  left(name,10) from profin_application;

     select t1.name ,timeadd('hour',8,t1.date),t3.name_template ,left(t3.name_template,3) ,substring(t3.name_template,6,3) 号,t4.material  ,t4.cust_spec ,
           t5.name ,case when left(t5.name,2)='20' then substring(t5.name,3,6) else left(t5.name,6) end pp,case when left(t5.name,2)='20' then substring(t5.name,9,2) else substring(t5.name,7,2) end GD ,right(t5.name,3) ,t6.name ,t8.name ,t2.lqty
            from mrp_production_report t1
            left join mrp_production_report_line t2 on t1.id=t2.line_id
            left join product_product t3 on t2.lproduct_id=t3.id
            left join product_template t4 on t3.product_tmpl_id=t4.id
        left join mrp_production_report_lot t5 on t5.id=t2.lot_id
        left join mrp_routing_workcenter t6 on t6.id=t2.lprocedure
            left join res_users t7 on t7.id=t2.lemployee
        left join res_partner t8 on t8.id=t7.partner_id
              where t2.lstate=2 and t6.name='分选' or t6.name='包装' and t1.company_id=4  and t1.date>='${sd} 0:00:00' and t1.date<='${ed} 23:59:59'

  • 相关阅读:
    android broadcast小结
    初学设计模式【7】单例模式——sington
    android之Service总结
    现代软件开发实现六面体
    牛顿迭代法求根
    实现顺序表的各种基本运算
    公共的分页类,包含jsp页面
    多项式拟合+高斯消元解方程组
    差商表及牛顿插值
    C#.NET 获取拨号连接 宽带连接
  • 原文地址:https://www.cnblogs.com/1314520xh/p/7227490.html
Copyright © 2011-2022 走看看