Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UNPIVOT Query

selvi mJul 22 2023

Hi Team,

i have table in this table has item startdate and qty
item startdate qty
it1 22-07-2023 10
it2 22-07-2023 20
it3 22-07-2023 20
it1 23-07-2023 10
it2 23-07-2023 20

i want below output

item 22-07-2023 22-07-2023
it1 10 10
it2 20 20
it3 20 0

I tried the query below, but it's not working. The FOR startdate is provided as hardcoded. Is there any automatic way to generate the dates dynamically? Please help me.

SELECT *
FROM (
SELECT item, startdate, qty
FROM valid_details
)
UNPIVOT (
qty FOR startdate IN (DATE '2023-07-22' AS "22-07-2023", DATE '2023-07-23' AS "23-07-2023")
)
ORDER BY item, startdate;

Thanks

This post has been answered by mathguy on Jul 22 2023
Jump to Answer
Comments
Post Details
Added on Jul 22 2023
4 comments
540 views