S.Kovic S.Kovic - 3 months ago 8
SQL Question

SQL COUNT within same select query

I'm wondering if its possible to count the records produced by a query within the same query?

SELECT HousesForRent.City
FROM HousesForRent
WHERE rooms >= 7

SELECT COUNT(rooms) AS seven_or_More
FROM HousesForRent
WHERE rooms >= 7;


I'v only managed to create it in another
SELECT
query.

Answer

Yes, it is possible, you just need to use the OVER clause:

SELECT  HousesForRent.City, COUNT(*) OVER() Total
FROM    HousesForRent
WHERE   (rooms >=7 );
Comments