2014-01-22 36 views
0

我有這樣的事情count行

With q as (some valid query), 
    r as (some other valid query) 

我希望得到的結果是在qr

的行數,所以我需要做的select(*) from qselect(*) from r

我如何在t-sql中做到這一點?

回答

1

如果你想要把它作爲列試試這個

With q as (some valid query), 
    r as (some other valid query) 
select COUNT(*) as total from q 
UNION ALL 
select COUNT(*) as total from r 

結果

total 
20054 
2548 

,那麼你就可以非常相似的建議是什麼@gbejic:

With q as (some valid query), 
    r as (some other valid query) 
select (SELECT COUNT(*) from q) as q, (SELECT COUNT(*) from r) as r 
+0

爲什麼工會都在這兩者之間? –

+0

你計算第一個表並添加另一個表。你會得到2行的計數 – Darka

+0

有沒有辦法使它成爲命名列? –

0
SELECT 
(select COUNT(*) from q) + (select COUNT(*) from r)