At a quick glance, your inline views are the issue. You are selecting the distinct Division_ID but not not selecting any other columns, but you are referring to other columns in the SELECT clause from those in-line views.
For example,
You select B.MAT from the main SELECT clause, which i'm guessing you want from the in-line view below
(Select DISTINCT DIVISION_ID FROM ODS.R_M) B
However, you are not selecting the MAT column in the in-line view above, but only the distinct Division_ID is being returned. There is no B.MAT column to select.
Without seeing the data it's hard to give you a solution for your specific problem. But you might want to include the columns you are selecting in the main SELECT clause in your in-line views. Here is a new in-line view B that should work:
(Select DISTINCT DIVISION_ID, MAT, ART, MAC FROM ODS.R_M) B
Now this will give you the unique combinations of Division_ID, MAT, ART and MAC. Not sure if that is what you are looking for. It might be easier to create separate views for those in-line views in their own queries, make sure those views are what you need, then use those to join. Example data would help.
- Peter
... View more