根据另一个表的日期选择列的当前值
我有4个表:
- 发票,包含输入日期。
- Invoice_Item包含产品COD。
- 产品,这里包含标准列,它仅显示当前标准值。
- product_hist(包含产品表的标准值更改)。
我试图根据发票输入日期选择product_hist的“标准”值(可以是Y'或'n'。
我的选择下面没有显示正确的值,
SELECT NT.INVOICE
, NT.PROVIDER
, NT.ENTRY
, NTI.PRODUCT
, P.COD
, P.NAME
, Nvl(P.STANDARD, 'Y') "STANDARD_ACTUAL"
, COALESCE ((SELECT To_Char(MAX(PH.DATE)) FROM PRODUCT_HIST PH
WHERE PH.COD = P.COD),
P.STANDARD, 'S') "STANDARD2"
FROM INVOICE NT
INNER JOIN INVOICE_ITEM NTI ON NT.NOTE = NTI.NOTE AND NT.PROVIDER = NTI.PROVIDER
INNER JOIN PRODUCTS P ON P.COD = NTI.PRODUCT
WHERE NT.ENTRY BETWEEN TO_DATE('01/01/2019','DD/MM/YYYY') AND TO_DATE('31/12/2019','DD/MM/YYYY')+0.99999
我想显示发票
在CoceSce列中输入(标准2)的当前值,而不是基于发票条目,
我3天了,不能使它起作用。如果有人能帮助我,将不胜感激。
I have 4 tables:
- INVOICE, contains the entry date.
- INVOICE_ITEM contains the product cod's.
- PRODUCTS, here contains the STANDARD column, It shows only the current standard value.
- PRODUCT_HIST (contains the standard value changes of the products table).
I'm trying to select the "standard" value (Can be 'Y' or 'N') of the product_hist based on the invoice entry date.
My select below isn't showing the correct values
SELECT NT.INVOICE
, NT.PROVIDER
, NT.ENTRY
, NTI.PRODUCT
, P.COD
, P.NAME
, Nvl(P.STANDARD, 'Y') "STANDARD_ACTUAL"
, COALESCE ((SELECT To_Char(MAX(PH.DATE)) FROM PRODUCT_HIST PH
WHERE PH.COD = P.COD),
P.STANDARD, 'S') "STANDARD2"
FROM INVOICE NT
INNER JOIN INVOICE_ITEM NTI ON NT.NOTE = NTI.NOTE AND NT.PROVIDER = NTI.PROVIDER
INNER JOIN PRODUCTS P ON P.COD = NTI.PRODUCT
WHERE NT.ENTRY BETWEEN TO_DATE('01/01/2019','DD/MM/YYYY') AND TO_DATE('31/12/2019','DD/MM/YYYY')+0.99999
I wanna show the current value when the invoice had an entry (STANDARD2)
In the COALESCE column I have the last value, it's not based on the invoice entry
I'm 3 days on it and cant make it work. Would be grateful if someone can help me, please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论