当前位置:网站首页>True question of MySQL interview (29) -- case - finding favorite movies

True question of MySQL interview (29) -- case - finding favorite movies

2022-06-23 05:41:00 Socialphobia_ FOGO

Find your favorite movies

A movie platform ( It's like Douban 、 The cat's eye film ) use 3 A table to record movie information .
“ Movie list ” In is the movie number 、 The movie name 、 Movie description information .
 Insert picture description here
“ Category table ” It's movie classification information , Categories include : Crime movies 、 love film 、 Science fiction film .
 Insert picture description here
“ Movie category table ” It's the corresponding movie ( The movie number in the movie table ) What kind of ( Movie category number in the category table )
 Insert picture description here
lookup “ Movie list ” The movie description information contains “ robot ” In the movie , Find out the corresponding movie category name and the number of movies , It is also required that the film category name corresponds to the number of films >=5 Ministry .

SELECT 
   Movie category name ,
  COUNT(*) AS  Number of films  
FROM
   Movie list  
  LEFT JOIN  Movie category table  USING ( Movie number ) 
  LEFT JOIN  Category table  USING ( Movie category number ) 
WHERE  Movie description information  LIKE '% robot %' 
GROUP BY  Movie category name  
HAVING  Movie category name  IN 
  (SELECT 
     Movie category name  
  FROM
     Movie category table  
    JOIN  Category table  USING ( Movie category number ) 
  GROUP BY  Movie category name  
  HAVING COUNT(*) >= 5)

give the result as follows :
 Insert picture description here

原网站

版权声明
本文为[Socialphobia_ FOGO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230355226654.html