如何获取总天数报告构建器(Oracle DB)

发布于 2025-02-13 18:02:57 字数 360 浏览 0 评论 0原文

从特定日期开始,我有一段时间用于总库存的报告。但是,我需要添加一列,以显示该材料已经存在了多少天。我该如何完成?

假设我的查询是:

MVT.INVT_LEV1,
MVT.INVT_LEV2,
MVT.INVT_LEV3,
MVT.INVT_LEV4,
INVT_ORG_RECD_DATE 
FROM M_INVT

INVT_ORG_RECD_DATE提供了收到材料中库存的日期。假设数据为07/05/22。我想要另一篇文章,说库存已经存在了两天。我该如何完成?如果这没有意义,我可以在整个查询中复制。

我想象第一个日期是该列中的日期,第二个日期是我正在运行报告的日期?还有一些系统需要如何弄清两者之间有多少天?

I have a report we have been using for quite some time for total inventory as of a specific date. However, I need to add a column that shows how many days this material has been in inventory. How do I accomplish this?

Let's say my query is:

MVT.INVT_LEV1,
MVT.INVT_LEV2,
MVT.INVT_LEV3,
MVT.INVT_LEV4,
INVT_ORG_RECD_DATE 
FROM M_INVT

INVT_ORG_RECD_DATE provides the date the material was received into our inventory. Let's say the data is 07/05/22. I want another column that says inventory has been with us for two days. How do I accomplish this? If this doesn't make sense I can copy over my entire query.

I would imagine the first date is the date in that column, and the second date would be the date I am running the report for? and some how need to system to figure out how many days in between?

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

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

发布评论

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

评论(1

我还不会笑 2025-02-20 18:02:57

最简单的选项是在查询中进行计算:

select invt_lev1, ...,
       --
       trunc(sysdate) - invt_org_recd_date as number_of_days
from m_invt

为什么trunc?因为sysdate返回日期和时间,因此您将获得分数数:

SQL> select sysdate as today,
  2         sysdate - date '2022-07-06' as diff_1,
  3         trunc(sysdate) - date '2022-07-06' diff_2
  4  from dual;

TODAY                   DIFF_1     DIFF_2
------------------- ---------- ----------
08.07.2022 06:59:51  2.2915625          2
                     ---------
                     without TRUNC
SQL>

另一个选择是在数据模型编辑器中创建公式列(单击适当的按钮在左侧工具栏中,并将其添加到包含其他字段的组中)。将其命名,例如cf_number_of_days并编辑其属性;您要使用的代码将是

return trunc(sysdate) - :invt_org_recd_date;

公式列表示返回一些值的函数(在您的情况下为数字)。


最后,将新字段添加到纸质布局编辑器中。我想你知道该怎么做。

The simplest option is to do the calculation within the query:

select invt_lev1, ...,
       --
       trunc(sysdate) - invt_org_recd_date as number_of_days
from m_invt

Why TRUNC? Because sysdate returns both date and time, so you'd get fractional number of days:

SQL> select sysdate as today,
  2         sysdate - date '2022-07-06' as diff_1,
  3         trunc(sysdate) - date '2022-07-06' diff_2
  4  from dual;

TODAY                   DIFF_1     DIFF_2
------------------- ---------- ----------
08.07.2022 06:59:51  2.2915625          2
                     ---------
                     without TRUNC
SQL>

Another option is to create a formula column in the Data Model Editor (click the appropriate button in the left-hand side toolbar and add it into the group that contains other fields). Name it e.g. CF_NUMBER_OF_DAYS and edit its properties; code you'd use would be

return trunc(sysdate) - :invt_org_recd_date;

as formula column represents a function that returns some value (a number, in your case).


Finally, add the new field into the Paper Layout Editor. I guess you know how to do that.

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