2014-09-13 70 views
0

我有一個包含12列的表。在SQL Server 2012的查詢中一起使用select *和count(*)

我需要一個計算COUNT(*)並選擇所有列的查詢。

我的意思是我想擁有這兩個查詢只是在一個查詢:

select * 
from mytable 
where OneOfTheColumns = something; 

select COUNT(*) 
from mytable 
where OneOfTheColumns = something; 

條件和表格是相同的。

我可以這樣做嗎?

非常感謝。

回答

3

您可以使用a window function

select *, 
     count(*) over() as total_count 
from mytable 
where OneOfTheFields = something; 
+0

非常感謝。我的問題解決了。最好的問候 – 2014-09-13 13:39:02