问题描述:

I have something like this

With q as ( some valid query),

r as (some other valid query)

I'd like the result to be the number of rows in q and r

so I need to do select(*) from q and select(*) from r

How can I do this in t-sql?

网友答案:

Try this one

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

Result

total
20054
2548

If you want to put it as columns, then you can very similar what @gbejic suggested:

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
网友答案:
SELECT 
(select COUNT(*) from q) + (select COUNT(*) from r)
相关阅读:
Top