admin管理员组文章数量:1134232
I have a Main
Table that I would like to add the "Goal
" column to, which will identify what section an item has gone through.
Table 1
stores separate data that labels the section and establishes a start
and end
depth. However, I have a Specified Depth
column that will control the final depth that an item will go through.
The "Goal" is to be able to effectively label what section/s the item has been through. I've thought about pivoting Table 1
, but sometimes there are many sections, so it would be very difficult to code for a pivot on every occasion. Is there a way that I'm not thinking of that could lead me to getting that "Goal
" column in there and be able to join Table 1
to the Main Table
?
I have a Main
Table that I would like to add the "Goal
" column to, which will identify what section an item has gone through.
Table 1
stores separate data that labels the section and establishes a start
and end
depth. However, I have a Specified Depth
column that will control the final depth that an item will go through.
The "Goal" is to be able to effectively label what section/s the item has been through. I've thought about pivoting Table 1
, but sometimes there are many sections, so it would be very difficult to code for a pivot on every occasion. Is there a way that I'm not thinking of that could lead me to getting that "Goal
" column in there and be able to join Table 1
to the Main Table
?
- 1 Can you please change the images to tabular markdown format data in text? – samhita Commented Jan 7 at 19:18
- 2 As per the question guide, please do not post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. – Dale K Commented Jan 7 at 19:49
- I don't understand the example. It looks like for each item you want the start-end-range sections the in-depth to out-depth range overlap with. 1=A, 2=A,B,C, 3=C,D, 4=D,E. But your result only shows D for item 4. And you mention the specifed_depth, but I don't see how this is involved. – Thorsten Kettner Commented Jan 8 at 8:50
1 Answer
Reset to default 0SELECT *
FROM "Main table" AS MT
JOIN "Table 1" AS T1
ON T1.Start BETWEEN MT."In Depth" and MT."Out Depth" OR
T1.Eend BETWEEN MT."In Depth" and MT."Out Depth"
With aggregation :
SELECT MT.*, LISTAGG(SECTION, ',') AS Goal
FROM "Main table" AS MT
JOIN "Table 1" AS T1
ON T1.Start BETWEEN MT."In Depth" and MT."Out Depth" OR
T1.Eend BE, TWEEN MT."In Depth" and MT."Out Depth"
GROUP BY Location, Item"In Depth", "Out Depth", "Sepcuified Depth"
本文标签: Oracle SQL Join Two Tables With 2 Interval Ranges and ConditionStack Overflow
版权声明:本文标题:Oracle SQL- Join Two Tables With 2 Interval Ranges and Condition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736781679a1952632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论