S.Kovic S.Kovic - 11 months ago 54
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

Answer Source

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

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