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?
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