Solved

Can you do a count() in a table without grouping other columns

Posted on 2014-09-11
3
394 Views
Last Modified: 2014-09-11
Basically what I am trying to do is get a table with all my cables, the number of conductors the cable is supposed to have, and the count of the cables in the table... To further illustrate here is the query I have

  SELECT CONDUCTOR.CABLE, TYPE_CODE.CONDUCTORS
    FROM CONDUCTOR, CABLE, TYPE_CODE
   WHERE CONDUCTOR.CABLE_ID = CABLE.CABLE_ID AND CABLE.ID = TYPE_CODE.ID
ORDER BY CABLE ASC;

The resulting table:
Cable      Conductors
1000A      3
1000A      3
1000B      3
1000B      3
1000B      3
1000C      3

what I want is this:
Cable      Conductors      Count(Cable)
1000A            3                     2
1000A            3                     2
1000B            3                     3
1000B            3                     3
1000B            3                     3
1000C            3                     1

Is this possible to do?
0
Comment
Question by:imonfireDAMMIT
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40317588
Try this (untested, just typed in):
 SELECT CONDUCTOR.CABLE, TYPE_CODE.CONDUCTORS,count(CONDUCTOR.CABLE) over(partition by CONDUCTOR.CABLE order by CONDUCTOR.CABLE) cable_count
    FROM CONDUCTOR, CABLE, TYPE_CODE
   WHERE CONDUCTOR.CABLE_ID = CABLE.CABLE_ID AND CABLE.ID = TYPE_CODE.ID
ORDER BY CABLE ASC;
0
 
LVL 1

Author Closing Comment

by:imonfireDAMMIT
ID: 40317605
Thanks. This worked perfectly.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 40317667
the order by in the OVER() clause isn't necessary unless you are doing a rolling count
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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

803 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