S.Kovic
S.Kovic

Reputation: 23

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.

Upvotes: 2

Views: 80

Answers (1)

Lamak
Lamak

Reputation: 70638

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

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

Upvotes: 4

Related Questions