sql - Optimize mysql query to select the values -


i having table following column names: audit_name, audit_choice , "slno" auto increment primary key , no use output data.

the audit_name can repeated , audit_choice values limited values "passed", "failed".

my query expected output is, getting number of "passed" counts , "failed" counts each "audit_name".

here query tried takes around 3-4 minutes execute around 1,000 records.

select audit_name,   (select count(*) passed audit p1      p1.audit_name=p2.audit_name , p1.audit_choice="passed") passed,   (select count(*) failed audit p3      p3.audit_name=p2.audit_name , p2.audit_choice="failed") failed   audit p2   group audit_name 

please suggest me how can optimize query.

select  audit_name,         sum(audit_choice = 'passed') passed,         sum(audit_choice = 'failed') failed    audit group         audit_name 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -