同一选择查询

时间:2016-09-01 14:11:16

标签: sql sql-server

我想知道是否可以计算同一查询中查询产生的记录?

SELECT HousesForRent.City
FROM HousesForRent
WHERE rooms >= 7

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

我只是设法在另一个SELECT查询中创建它。

1 个答案:

答案 0 :(得分:3)

是的,有可能,您只需要使用OVER子句:

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