| 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?
Now that I'm embarassed for not having remembered how to do the simple case, let me further embarass myself by asking how to do a slightly more complex case. Say the initial table looks like this:
Firstname Lastname Order
--------- -------- -----
JOHN SMITH 10001
JOHN SMITH 10002
JOHN SMITH 10003
TIM JONES 10004
TIM JONES 10005
TIM JONES 10006
TIM JONES 10007
JAMES DOE 10008
JAMES DOE 10009
I want to generate this output:
Firstname Lastname Tally
--------- -------- -----
JOHN SMITH 3
TIM JONES 4
JAMES DOE 2
I don't understand the ORA-973 error I'm getting, and I have no reference material to look it up in:
SQL> select firstname, lastname, count(lastname) from users; select firstname, lastname, count(lastname) from users
*
ERROR at line 1:
ORA-00937: not a single-group group function
SQL> select firstname, lastname, count(*) from users; select firstname, lastname, count(*) from users
*
ERROR at line 1:
ORA-00937: not a single-group group function
SQL> select firstname, lastname, count(firstname) from users; select firstname, lastname, count(firstname) from users
*
ERROR at line 1:
ORA-00937: not a single-group group function
What's the syntax I'm looking for? Also, are there any good SQL language references on the web? (AltaVista wasn't able to find anything useful.)
--
_/_/_/ 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 Thu Jul 24 1997 - 00:00:00 CDT
![]() |
![]() |