?
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
Medium Priority
?
55 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 2000 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 49

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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…
Suggested Courses

762 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