Solved

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

Posted on 2014-09-11
3
389 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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Add 0 to end of Number 21 71
Pl/SQL Query 31 61
PL/SQL Search for multiple strings 5 20
history tablespace temp usage 2 15
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…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

708 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

18 Experts available now in Live!

Get 1:1 Help Now