简体   繁体   中英

SQL find number of columns

数据库架构

Ok, I have this logical scheme about movies, actors, directors, etc. in an SQL database, and I want to create a query that returns me all movies with more than 2 copies.

I've been trying, but I cant get it right, can anybody help me?

The right query is something like this:

SELECT m.title, COUNT(*)
FROM movies m JOIN
     copies c 
     ON m.mid = c.mid 
GROUP BY m.title
HAVING COUNT(*) > 2;

If you don't need the title, then the JOIN is not even necessary:

SELECT c.mid, COUNT(*)
FROM copies c 
GROUP BY c.mid
HAVING COUNT(*) > 2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM