MySQL Forums
Forum List  »  General

Re: count() question
Posted by: James Day
Date: March 28, 2005 08:42PM

Total number of pending invoices, all clients:

select count(*) from Invoices where not Invoices.paid;

Count for each client:

select organization, count(*) from Invoices, clients where clients.clientID=Invoices.clientID and not Invoices.paid group by Invoices.clientID;

You probably want to add an order by organization.

If the query is common, an index on Invoices fields paid, clientID will help speed, since it'll be a covering index and remove the need to load the data record to check whether the invoices have been paid.

Options: ReplyQuote


Subject
Written By
Posted
March 24, 2005 08:01PM
Re: count() question
March 28, 2005 08:42PM
March 30, 2005 03:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.