Count specific errors in a database [RESOLVED]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

Count specific errors in a database [RESOLVED]

Post by spec36 »

Hi Guys,

I am new to Mysql & PHP and don't know exactly what function I should be looking at for this.

I have a database of some 1 million records, there is one field in the database that contains an error code. I need to search through all records and count the amount of individual errors.

EXAMPLE:
----------------
Field name -> event_desc
ErrorManager.storeError(): name:7725878458375 time: Tue Jun 03 12:59:19 EDT 2010 code: 9909 data:667,D,555,345345354

I need to somehow read the "code: 9909" and count the total amount of them that exist between a specified date range in the database. There are also multiple other error numbers that need to be counted as well.

Any help would be greatly appreciated.

Thanks,
Last edited by spec36 on Tue Jul 06, 2010 1:57 pm, edited 1 time in total.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Count specific errors in a database

Post by VladSun »

You need to use COUNT() function and GROUP BY clause.
Take a look at the manuals about them.

And if you need to count the appearance of a single error code you should use a simple COUNT() together with WHERE clause query.
There are 10 types of people in this world, those who understand binary and those who don't
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

Re: Count specific errors in a database

Post by spec36 »

Thanks for the help.

I ended up using the following mysql query for this.

Code: Select all

select '4444' as 'error code', count(*) as 'total' from table where field like '%error: 4444%'
Post Reply