miércoles, 8 de octubre de 2008

SQL select con count-if

By embedding an IF() function within a COUNT() function, you can gather several counts on the same table at once.

If you use an IF() function to evaluate the condition, and return NULL if it's false, you can collect both totals in a single query:

SELECT COUNT(IF(something="this",1, NULL)) AS somethingcount, COUNT(*) AS total FROM mytable;

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

No hay comentarios: