Solved

how to write case statement or loop statement in simple sql query for same product with multiple sub products??

Posted on 2016-09-01
4
49 Views
Last Modified: 2016-10-22
how to write case statement or loop statement in simple sql query for same product with multiple sub products??


eg If I have product computer then sub products are like laptop,desktop,harddisk,ram etc

table is like productno | productsubno | productdesc|
                         1                         2                              laptop
                          1                          2                           desktop
                         1                         2                            harddisk                     like this...

and I want output like  

product            productsubcode   desc1       desc2          desc3            etc...
1                                         2             laptop        desktop       hardisk      


Please help in simple sql query...
0
Comment
Question by:newdeveloper india
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
Abhimanyu Suri earned 500 total points
ID: 41779802
SELECT productno,
         productsubno,
         LISTAGG (productdesc, ',') WITHIN GROUP (ORDER BY productdesc)
    FROM TABLE_X
GROUP BY productno, productsubno

o/p :

1 2 laptop,desktop,hardisk

You can achieve output without commas by modifying
" LISTAGG (productdesc, ',') WITHIN GROUP (ORDER BY productdesc)"  TO
" LISTAGG (productdesc, '      ') WITHIN GROUP (ORDER BY productdesc)"

You can publish it as a csv by using

  SELECT productno||','||
         productsubno||','||
         LISTAGG (productdesc, ',') WITHIN GROUP (ORDER BY productdesc)
    FROM TABLE_X
GROUP BY productno, productsubno

1,2,laptop,desktop,hardisk
0
 

Author Comment

by:newdeveloper india
ID: 41785837
error found like this..

 FROM keyword not found where expected
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41785860
which query did you use? did you transcribe it accurately?

i.e. it is hard for use to know what that error relates to. Please copy/paste the EXACT query you used and the EXACT error message.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SYS password changed. Now can't log in as SYS 27 62
error in oracle form 11 52
Select the 2 most recent visit dates 5 30
only show the last 365 days 6 35
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question