Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I write a "tally" query in SQL?
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!
>