Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I write a "tally" query in SQL?

Re: How do I write a "tally" query in SQL?

From: Martin Bronstein <Martin.Bronstein_at_trw.com>
Date: 1997/07/23
Message-ID: <33D5FE8B.25D5@trw.com>#1/1

Brian Kendig wrote:
>
> I want to find out how to write a SQL query that tallies up, for each
> distinct value in a column, how many rows that value appears in. For
> example, given a table like this:
>
> Name Order
> ----- -----
> SMITH 10001
> SMITH 10002
> SMITH 10003
> JONES 10004
> JONES 10005
> JONES 10006
> JONES 10007
> DOE 10008
> DOE 10009
>
> I want to generate this output:
>
> Name Tally
> ----- -----
> SMITH 3
> JONES 4
> DOE 2
>
> I can't figure out how to write a SQL query for this (that would run in
> SQL*Plus). Can someone help? Thanks!
>

Brian,

SELECT name, Count(name) FROM my_table
GROUP BY name;

Martin Bronstein Received on Wed Jul 23 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US