1

I have the following query:

SELECT release_year
FROM films
GROUP BY release_year
HAVING COUNT(title) > 200;  

which returns the years in which the total number of films released is greater than 200.

The result prints a list of years that satisfy the criteria. 13 years do.

How do I print out just the number 13 instead?

I've tried the top answer in this solution: How to get total number of rows in a executed select statement?

The @@ROWCOUNT didn't work for me (I'm using PostgreS, maybe that's the issue) And when I tried

SELECT COUNT(*) OVER() 
FROM films
GROUP BY release_year
HAVING COUNT(title) > 200; 

I got a single column, count, with 13 rows of 13 printed.

How do I just get the single number of the row count of the 1st query, 13, printed once?

Thanks!

shoestringfries
  • 279
  • 4
  • 18

1 Answers1

5

You may use sub-query:

SELECT COUNT(*) FROM (
    SELECT release_year
    FROM films
    GROUP BY release_year
    HAVING COUNT(title) > 200
) AS tbl;
cn007b
  • 16,596
  • 7
  • 59
  • 74