物化视图中的动态计算

发布于 2024-11-29 07:23:12 字数 1004 浏览 2 评论 0原文

我有一个问题,我创建了一个完美运行的物化视图。但现在我需要用我认为的数据进行一些计算。该视图包含在不同项目中工作的员工的工作时间。每个项目都有员工必须完成项目的固定时间 (time_available)。为了更好地展示,我将工作时间汇总为每月。我想要在这里完成的是“简单”减去“项目的固定金额”减去员工的“工作时间”。 这里的问题是有些项目的持续时间超过一个月。当然,我每个月的所有值都在一个元组中。因此,当我的项目有 3 个月的工作时间时,我的视图如下所示:

MV_Working_Hours:

Project --- Time_Available --- DATE --- Employee --- Working Days
Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days
Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days
Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days

我想要做的是计算剩余天数,如下所示:

Project --- Time_Available --- DATE --- Employee --- Working d in Month ---remaining days
Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days --- 35 Days
Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days --- 19 Days <--- I get here 34 which is for my need wrong !!!
Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days --- 3 Days

有没有一种方法可以用“仅”sql 来实现这一点,或者我有在 OWB 中使用 pl/sql?我使用 OWB 版本 11gR2

谢谢

I have a problem I created a materialized view which works perfectly. But now I need to perform some calculations with the data in my view . The view contains the working hours of employees who worked in different projects. Every project has a fixed amount of time (time_available) in which the employee has to finish the project. I aggregated the working hours to month for better presentation. What I want to accomplish here is a "simple" subtraction of "fixed amount for a project" minus "working hours" for the employee.
The problem here is that some project have duration of more that just one month. Naturally all my values are in one tuple for every month. So when I have 3 month of working hours for a project my view looks like this:

MV_Working_Hours:

Project --- Time_Available --- DATE --- Employee --- Working Days
Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days
Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days
Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days

What I want to do is to calculate the remaining days like this :

Project --- Time_Available --- DATE --- Employee --- Working d in Month ---remaining days
Project A --- 50 Days --- 2011-05 --- Mr. A --- 15 Days --- 35 Days
Project A --- 50 Days --- 2011-06 --- Mr. A --- 16 Days --- 19 Days <--- I get here 34 which is for my need wrong !!!
Project A --- 50 Days --- 2011-07 --- Mr. A --- 16 Days --- 3 Days

Is there a way to realize this with "just" sql or do I have to use pl/sql in the OWB? I use the OWB version 11gR2

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅暮の光 2024-12-06 07:23:12

您应该能够使用分析函数来生成运行总计。像这样的东西

SELECT project,
       time_available,
       date_column,
       employee,
       working_days_in_month,
       time_available - 
         sum(working_days) over (partition by project 
                                     order by date) remaining_days
  FROM mv_working_hours

You should be able to use analytic functions to generate the running total. Something like

SELECT project,
       time_available,
       date_column,
       employee,
       working_days_in_month,
       time_available - 
         sum(working_days) over (partition by project 
                                     order by date) remaining_days
  FROM mv_working_hours
小兔几 2024-12-06 07:23:12

您应该能够使用分析 SQL 函数来完成此操作。

11gR2 http://download.oracle.com/docs/ cd/E14072_01/server.112/e10810/analysis.htm

SUM( "Working Days" )
  OVER (PARTITION BY "Project", "Employee"
  ORDER BY "DATE" 
  ROWS UNBOUNDED PRECEDING)

您应该能够从“Time_Available”(您有可能返回负值,用零替换这些值也可以在 SQL 中处理)


顺便说一句,我忍不住喜欢您为结果选择的标题。 .. “扩孔日”

根据项目的不同,A 先生可能会认为栏目标题是适当且合理的。

You should be able to do this with analytic SQL functions.

11gR2 http://download.oracle.com/docs/cd/E14072_01/server.112/e10810/analysis.htm

SUM( "Working Days" )
  OVER (PARTITION BY "Project", "Employee"
  ORDER BY "DATE" 
  ROWS UNBOUNDED PRECEDING)

You should be able to subtract that from "Time_Available" (you'll have a potential for returning negative values, replacing those with zeros can be handled in SQL as well)


BTW, I can't help but like your chosen title for the result... "reaming days"

Depending on the project, Mr. A might feel that column title is appropriate and justified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文