博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用with 创建视图
阅读量:5124 次
发布时间:2019-06-13

本文共 906 字,大约阅读时间需要 3 分钟。

语法  : 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;

 

转载于:https://www.cnblogs.com/a6948076/p/10169604.html

你可能感兴趣的文章
嵌入式软件设计第8次实验报告
查看>>
算法和数据结构(三)
查看>>
Ubuntu下的eclipse安装subclipse遇到没有javahl的问题...(2天解决了)
查看>>
alter database databasename set single_user with rollback IMMEDIATE 不成功问题
查看>>
WCF揭秘——使用AJAX+WCF服务进行页面开发
查看>>
【题解】青蛙的约会
查看>>
IO流
查看>>
mybatis调用存储过程,获取返回的游标
查看>>
设计模式之装饰模式(结构型)
查看>>
面向对象的设计原则
查看>>
Swift3.0服务端开发(三) Mustache页面模板与日志记录
查看>>
EntityFrameWork 实现实体类和DBContext分离在不同类库
查看>>
autopep8
查看>>
GIT在Linux上的安装和使用简介
查看>>
基于C#编程语言的Mysql常用操作
查看>>
s3c2440实验---定时器
查看>>
MyEclipse10安装SVN插件
查看>>
[转]: 视图和表的区别和联系
查看>>
Regular Experssion
查看>>
图论例题1——NOIP2015信息传递
查看>>