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;
  • 相关阅读:
    阮一峰的网络日志 算法
    Problem 2184 逆序数还原
    vs项目中使用c++调用lua
    多例模式
    关于O_APPEND模式write的原子性
    清醒
    编译时,遇到Couldn't build player because of unsupported data on target platform的解决方式
    把JavaScript和CSS放到外部文件里
    SSM框架——具体整合教程(Spring+SpringMVC+MyBatis)
    MMORPG网页游戏斩仙录全套源代码(服务端+client)
  • 原文地址:https://www.cnblogs.com/a6948076/p/10169604.html
Copyright © 2011-2022 走看看