zoukankan      html  css  js  c++  java
  • 使用with 创建视图

    语法  : create  view  as  with   a  as () , select  *  from  a  ;

    CREATE VIEW pms_work_hour_view
    AS
       WITH t
            AS (SELECT id,
                       create_name AS name,
                       project_number AS parent_id,
                       (end_date - begin_date) AS times,
                       ROUND ( (end_date - begin_date) / 3600000, 2) AS work_hour
                  FROM PMS_USER_WORK_HOUR_LOG
                 WHERE status = '2'),
            tt
            AS (SELECT a.project_code AS id,
                       a.project_name AS name,
                       splitByUnderLine (a.project_code) AS parent_id,
                       b.times,
                       ROUND (b.times / 3600000, 2) AS work_hour
                  FROM PMS_SCHEDULE_MANAGEMENT a
                       LEFT JOIN (  SELECT parent_id, SUM (times) times
                                      FROM t
                                  GROUP BY parent_id) b
                          ON b.parent_id = a.project_code),
            ttt
            AS (  SELECT DISTINCT splitByUnderLine ( parent_id) AS id,
                                  '' AS name,
                                  '0' AS parent_id,
                                  SUM (times) AS times,
                                  ROUND (SUM (times) / 3600000, 2) AS work_hour
                    FROM tt
                GROUP BY parent_id)
       SELECT * FROM t
       UNION
       SELECT * FROM tt
       UNION
       SELECT * FROM ttt;
  • 相关阅读:
    http 301 和 302的区别
    移动端与PHP服务端接口通信流程设计(增强版)
    导出大量数据到excel表
    c#中两种不同的存储过程调用与比较
    sql存储过程几个简单例子
    高级搜索指令
    SEO 百度后台主动推送链接
    C#利用Web Service实现短信发送(转)
    webservice测试实例
    克服演讲紧张的10个技巧
  • 原文地址:https://www.cnblogs.com/a6948076/p/10169604.html
Copyright © 2011-2022 走看看