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!

Using SQL - get data in specific columns

JorgelinaMay 26 2020 — edited May 28 2020

Hi,

Sorry if the subject is not correct, but I am not sure how is the best way to sum up the issue I am having.

I have the following data (that is already coming from another  select sentence):

A                              B                                       C

TYPE1                    ZZA                                   20.50

TYPE1                    ZZB                                   32.00

TYPE1                    ZZC                                  35.25

TYPE1                    ZZB                                   38.00

TYPE1                    ZZD                                   40.00

TYPE2                    XXA                                   16.00

TYPE2                    XXB                                   17.00

TYPE2                    XXB                                    22.00

For each TYPE1 and TYPE2 the amount of rows can vary. (There could also be a TYPE3, 4, etc; but I'd rather try to focus the issue in just 2, though TYPE1/TYPE2, is also a variable name).

What I need to produce is:

TYPE1                                                   TYPE2

ZZA - 20.50                                            XXA - 16.00

ZZB - 32.00                                            XXB - 17.00

ZZC - 35.25                                            XXB - 22.00

ZZB - 38.00

ZZD - 40.00

Is this possible just with an sql query?

Is the only choice I have to create something similar to a dynamic query with lots of "select  ZZA-20.50 type1, XXA-16.00 type2  from dual      union all     select ZZB-32.00 type1,  XXB-17.00 type2   union all .... " and so on?

I would rather not, since, there is more data than just 2 columns, and the place where I would be returning the dynamic query to then be executed, cannot hold more than just 4000 characters (a limitation on APEX for what I am trying to achieve).

Maybe someone can hint me on the right direction on how to solve this?

Thanks!

This post has been answered by odie_63 on May 27 2020
Jump to Answer
Comments
Post Details
Added on May 26 2020
6 comments
760 views