0

我只需要在下面添加每个计数的总计,这对我不起作用,我得到“关键字'SELECT'附近的语法不正确。”:

DECLARE @total int

SET @total = Count(some select statement)

@total = @total + Count(some select statement)
@total = @total + Count(some select statement)
@total = @total + Count(some select statement)
.. and so on

-- now return the grand total
select @total

或者,如果您认为有更简单或更有效的方法来做到这一点,我也全神贯注。

4

1 回答 1

0
declare @total int = 0

select @total += count(*) from (select 1 col1) a
select @total += count(*) from (select 1 col1) a
select @total += count(*) from (select 1 col1) a

select @total
于 2012-08-30T07:20:26.277 回答