Home » SQL & PL/SQL » SQL & PL/SQL » SQL Query (Oracle 10g)
SQL Query [message #622951] Tue, 02 September 2014 08:04 Go to next message
vino06cse57
Messages: 131
Registered: July 2011
Location: chennai
Senior Member
Hi All

I need a SQL query to Fetch the Output as shown
Table:ACCOUNT_SUMMARY

prod_id Cust_id

101       AAA
101       BBB
101       CCC
102       AAA
103       AAA
102       CCC


Table : Product

Prod_id Prod_desc
101       Home_loan
102       Vehicle loan
103       Educational Loan


Expected Output: 

Cust_id  Prod_desc
AAA      Home_loan
AAA      Vehicle loan
AAA      Educational Loan 


Objective:I need the Customer id who has all the three Products
Regards
Vinoth


Lalit : Fixed typo in product from "19g" to "10g"

[Updated on: Tue, 02 September 2014 10:24] by Moderator

Report message to a moderator

Re: SQL Query [message #622955 is a reply to message #622951] Tue, 02 September 2014 08:17 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Your first objective should be to post accordingly to the forum rules that is with a test case.

Re: SQL Query [message #622962 is a reply to message #622955] Tue, 02 September 2014 10:26 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
@OP, hope you meant 10g and not 19g. I have edited the field. Please let us know if it's correct now.

Also, please mention a better topic title other than "SQL query". It is quite obvious that your question is about SQL itself, in this particular forum.

[Updated on: Tue, 02 September 2014 12:15]

Report message to a moderator

Re: SQL Query [message #622968 is a reply to message #622951] Tue, 02 September 2014 12:43 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
vino06cse57 wrote on Tue, 02 September 2014 09:04
I need a SQL query to Fetch the Output as shown


A hint: partitioned outer join + analytic count.

SY.
Re: SQL Query [message #623047 is a reply to message #622951] Wed, 03 September 2014 11:59 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
WITH T AS (
           SELECT  CUST_ID,
                   PROD_DESC,
                   COUNT(*) OVER(PARTITION BY A.CUST_ID) CNT1,
                   COUNT(A.PROD_ID) OVER(PARTITION BY A.CUST_ID) CNT2
             FROM      ACCOUNT_SUMMARY A
                        PARTITION BY(CUST_ID)
                   RIGHT JOIN
                       PRODUCT P
                     ON A.PROD_ID = P.PROD_ID
          )
SELECT  CUST_ID,
        PROD_DESC
  FROM  T
  WHERE CNT2 = CNT1
/


SY.
Previous Topic: Find missing sequence number between given range
Next Topic: pragma autonomous
Goto Forum:
  


Current Time: Thu Apr 25 06:51:36 CDT 2024