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: Ben Harmon <benh_at_dascom.com>
Date: 1997/07/23
Message-ID: <5r5g1h$el5@news9.noc.netcom.net>#1/1

Cool, an easy one!

SELECT name, COUNT(*) tally
FROM tally_table
GROUP BY name;

In article <bskendigEDs67r.xp_at_netcom.com>, bskendig_at_netcom.com (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!
>



Ben Harmon
ben_at_dascom.com.nospam
**Please remove .nospam suffix if you want to mail me**
Received on Wed Jul 23 1997 - 00:00:00 CDT

Original text of this message

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