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 -> How do I write a "tally" query in SQL?

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

From: Brian Kendig <bskendig_at_netcom.com>
Date: 1997/07/23
Message-ID: <bskendigEDs67r.xp@netcom.com>#1/1

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!

-- 
_/_/_/   Be insatiably curious.                 Je ne suis fait comme aucun
/_/_/    Ask "why" a lot.                de ceux que j'ai vus; j'ose croire
_/_/                           n'etre fait comme aucun de ceux qui existent.
  /    Brian Kendig         Si je ne vaux pas mieux, au moins je suis autre.
 /    bskendig_at_netcom.com                                       -- Rousseau
     http://home.netscape.com/people/brian/
Received on Wed Jul 23 1997 - 00:00:00 CDT

Original text of this message

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