GROUP BY with 3 tables [message #649728] |
Mon, 04 April 2016 21:08 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/5c7a97f1dac6a61b298fe4475adcae3c?s=64&d=mm&r=g) |
myoratom
Messages: 1 Registered: April 2016
|
Junior Member |
|
|
Hi,
Below are my 3 tables.
1) ORDER_HEADER ( OH_NUM, customer_ID) - OH number is unique key
2) ORDER_LINE ( OL_ID, OH_NUM , PROD_ID ) - OL Line ID is unique key
3) PRODUCT__DETAIL table ( PROD_ID , PROD_GROUP)
Now I want to write a SQL to find the count of Orders group by PROD Group
select PROD_GROUP, count(1)
from ORDER_HEADER OH, ORDER_LINE OL, PRODUCT_DETAIL PD
WHERE OH.OH_NUM =OL.OH_NUM
AND OL.PROD_ID = PD.PROD_ID
The above query is giving incorrect count. Can you please help?
|
|
|
|
Re: GROUP BY with 3 tables [message #649731 is a reply to message #649728] |
Tue, 05 April 2016 00:30 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](http://www.orafaq.com/forum/images/custom_avatars/102589.gif) |
Michel Cadot
Messages: 68665 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote:The above query is giving incorrect count.
It does not return any count as it is not a valid syntax.
Note: table ORDER_HEADER is useless to answer the question, you only need the 2 other ones 'assuming the question is the number of orders for each PROD_GROUP).
|
|
|