I have a sql table which has columns like ITEM_ID, FROM_QUANTITY, TO_QUANTITY, LIST_PRICE. Now every item should have a FROM_QUANTITY from 1 to 12 and a null in FROM_QUANTITY.
Now in order to check which QUANTITY is missing from ITEM in table , I have written a SQL query which will print None if the FROM_QUANTITY is not there.
The query is working as expected. Just that each item also has a null value in quantity and has some price associated with it. But my query is Showing null as list price for it.
Here is my query
with pl as (
select DISTINCT ITEM_ID, FROM_QUANTITY,TO_QUANTITY, coalesce(to_char(list_price), 'NONE') as list_price
from PRICELIST_LINE
where item_id IN ('XYZ') and
PRICELIST_HDR_KEY in (select Pricelist_Hdr_Key
from PRICELIST_HDR
where PRICELIST_NAME IN ('ABC') and
SELLER_ORGANIZATION_CODE IN ('100')
) and SYSDATE < END_DATE_ACTIVE
)
select i.item_id, u.from_quantity, pl.to_quantity,pl.list_price
from (select distinct item_id from pl) i cross join
(select '1' as from_quantity from dual union all
select '2' as from_quantity from dual union all
select '3' as from_quantity from dual union all
select '4' as from_quantity from dual union all
select '5' as from_quantity from dual union all
select '6' as from_quantity from dual union all
select '7' as from_quantity from dual union all
select '8' as from_quantity from dual union all
select '9' as from_quantity from dual union all
select '10' as from_quantity from dual union all
select '11' as from_quantity from dual union all
select '12' as from_quantity from dual union all
select '' as from_quantity from dual
) u left join
pl
on pl.item_id = i.item_id and pl.from_quantity = u.from_quantity;
Now the Output for this is like:
ITEM_ID FROM_QUANTITY TO_QUANTITY LIST_PRICE
------- ------------- ----------- ----------
ABC 1 2 100
ABC
Expected :
ITEM_ID FROM_QUANTITY TO_QUANTITY LIST_PRICE
------- ------------- ----------- ----------
ABC 1 2 100
ABC 200