[英]Oracle: select week of the year according to an input list
I had a two tables who looks like:我有一张看起来像的两张桌子:
Table A:
ORG_DATE
03/04/2018
02/10/2019
17/12/2018
Table B:
Start_date End_Date Week_of_Yr
01/04/2018 08/04/2018 2018041
01/10/2019 08/10/2019 2019101
14/12/2018 21/12/2018 2018123
The goal is to achieve a table who looks like:目标是实现一个看起来像这样的表:
ORG_DATE Week_of_Yr
03/04/2018 2018041
02/10/2019 2019101
17/12/2018 2018123
Simply assign the correct week of the year when the field ORG_DATE from table A, falls between start_date and end_date of table B.当表 A 中的字段 ORG_DATE 落在表 B 的 start_date 和 end_date 之间时,只需指定一年中的正确星期。
So far i tried the following because there aren't fields for making a possible join between the tables:到目前为止,我尝试了以下操作,因为没有用于在表之间进行可能连接的字段:
SELECT
Week_of_Yr
FROM TABLE B
WHERE TO_DATE((SELECT
TO_CHAR(A11.ORG_DATE, 'DD/MM/YYYY') ORG_DATE
FROM TABLE_A A11
GROUP BY A11.ORG_DATE), 'DD/MM/YYYY') BETWEEN Start_date AND End_Date;
However, the query doesn't accept a list as an input.但是,查询不接受列表作为输入。 Any ideas ?
有任何想法吗 ?
Thanks谢谢
Just join them checking the org_date
falls in between the start_date
and end_date
in the ON
clause.只需加入他们,检查
org_date
在ON
子句中的start_date
和end_date
之间。
SELECT a.org_date,
b.week_of_yr
FROM a
LEFT JOIN b
ON b.start_date <= a.org_date
AND b.end_date > a.org_date;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.