2

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.

4
  • So, what would you expect the output to look like? Commented Sep 1, 2016 at 14:12
  • A total at the end of the results, if that is possible. Commented Sep 1, 2016 at 14:18
  • You might want to edit your question and make that clear. Show what the output data would look like. Commented Sep 1, 2016 at 14:20
  • if you want to have only one line you want to use UNION Commented Sep 1, 2016 at 14:20

1 Answer 1

4

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

SELECT  HousesForRent.City, COUNT(*) OVER() Total
FROM    HousesForRent
WHERE   (rooms >=7 );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.