SQL Query [message #622951] |
Tue, 02 September 2014 08:04 |
|
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 #622962 is a reply to message #622955] |
Tue, 02 September 2014 10:26 |
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 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
vino06cse57 wrote on Tue, 02 September 2014 09:04I 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 |
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.
|
|
|