SQL query

Get help on databases - MySQL, Oracle, Access, etc.
Post Reply
GrimStoner
Registered User
Posts: 716
Joined: 08 Oct 2004, 02:00
Contact:

SQL query

Post by GrimStoner »

Hi

I need help on a SQL query...

Suppose I have a db with three fields...

1. ID
2. CellNumber
3. Transaction

I need a query to return the number of specific transactions per cellnumber. i.e... if the data were as follows :

1 0821234567 SMS
2 0821234567 MMS
3 0821234567 SMS
4 0821234567 SMS

I need the query to return the following :

1 0821234567 SMS 3
2 0821234567 MMS 1
xumwun
Registered User
Posts: 133
Joined: 14 Apr 2006, 02:00
Contact:

Post by xumwun »

you could try this.

select id, cellnumber, transaction, count(transaction) group by cellnumber
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Code: Select all

SELECT MyTable.CellNumber, MyTable.Transaction, COUNT(MyTable.Transaction) FROM MyDb.ownr.MyTable WHERE (some_clause) GROUP BY MyTable.CellNumber, MyTable.Transaction ORDER BY MyTable.CellNumber, MyTable.Transaction
Most people would sooner die than think; in fact, they do so - Bertrand Russel
GrimStoner
Registered User
Posts: 716
Joined: 08 Oct 2004, 02:00
Contact:

Post by GrimStoner »

When I try that, I get the following error message :

You tried to execute a query that does not include the specified expression transaction as part of an aggregate function. (Error 3122)
GrimStoner
Registered User
Posts: 716
Joined: 08 Oct 2004, 02:00
Contact:

Post by GrimStoner »

Thx Rustypup... Seems like it's a workin'...
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

:wink: good news..

remember, grouping requires that you specify each distinct column... at least, in vanilla sql it does...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Post Reply