从依赖查询中计算行数

时间:2014-01-22 14:34:03

标签: sql tsql

我有类似的东西

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

我希望结果是qr

中的行数

所以我需要select(*) from qselect(*) from r

我怎样才能在t-sql中执行此操作?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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