Solved

PL/SQL Group by

Posted on 2016-08-11
2
42 Views
Last Modified: 2016-08-11
Hello experts,

So it is needed to know which Owners have the most Protocols
and how many.
A query was crafted

Select owner_ID, SUM(protocol_id) as CNT
from ccm_protocol
group by owner_ID
--having SUM(protocol_id) between 1 and 601000
order by CNT desc

which returned
Owner_ID  CNT
258490      2631271323
306118      2435400026
296588      2261418059
207643      1916887537
212733      1866463289
202729      1729376813
430247      1690954678
213027      1670415116
213978      1601271602
257757      1593747213

Which blew my mind cause I think this says
that Owner_ID 258490 has 261 million protocols.
So the query was input

Select Owner_id, protocol_id
from ccm_protocol
where owner_id = 258490

which returned 1872 rows.

So there is something wrong with the GROUP BY query.

How can I get a list of OWNER_IDs with the number of
Protocols for each OWNER_ID?

Thanks.

Allen in Dallas
0
Comment
Question by:9apit
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
you have to count and not to Sum

Select owner_ID, count(protocol_id) as CNT
from ccm_protocol
group by owner_ID
--having SUM(protocol_id) between 1 and 601000
order by CNT desc

Open in new window

0
 

Author Closing Comment

by:9apit
Comment Utility
Well done. Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
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 how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now