mysql - Most Efficient way to write HAVING condition -


i completing more join operations tutorial of sqlzoo , encountered following code answer #12:

select yr,count(title)  movie  join casting  join actor    on actorid=actor.id , movie.id=movieid name='john travolta' group yr  having count(title)= (select max(c) (select yr, count(title) c  movie  join casting on movie.id=movieid join actor   on actorid=actor.id name='john travolta' group yr) t ) 

is there not more concise way express code?

yes. if understand quesiton correctly more simple.

select yr,count(title)     movie join casting on movie.id=movieid         join          actor   on actorid=actor.id name='john travolta' group yr having count(title) > 2  

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -