MySQL optimized Count () function

 

demand

 

Investigate the number of movies in 2006 and 2007 in one SQL.

 

 

Distinguish between count (*) and count (id)

 

We cannot directly use count (*) to query, because when there is no movie in a certain year, this field cannot be found

 

Instead, use count (id)

select count(release_year='2006' or null) as '06films',count(release_year='2007' or null) as '07films' from film;

 

 

Published 568 original articles · Like 180 · Visits 180,000+

Guess you like

Origin blog.csdn.net/Delicious_Life/article/details/105603680