Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-09-11
3
395 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 74

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web Service from a stored procdure oracle 10 58
Oracle Listener Not Starting 11 52
oracle DR - data guard failover. 18 46
oracle forms question 22 40
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…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

856 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