Solved

PL/SQL Group by

Posted on 2016-08-11
2
54 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41752225
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
ID: 41752837
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Listener Not Starting 11 53
PL/SQL Two changes 7 34
pivot rows to columns 1 35
Procedure syntax 5 40
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

830 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