select sum(amount),(select sum(a.amount)
from 表1 a
where a.date1<='2008-10-01'
) as amount1 from 表1
where date1>='2008-10-01' and oper_date<='2008-10-31'
----
declare @s varchar(8000)
set @s=''
select @s=@s+','+''''+rtrim(amount)+''''
from
(
select sum(amount) from 表1
where date1>='2008-10-01' and oper_date<='2008-10-31'
union
select sum(amount) from 表1
where date1<='2008-10-01'
)T
print @s
select right(@s,len(@s)-1) as amount
SELECT SUM(CASE WHEN Date1>='2008-10-1' THEN Amount END) AS AmountInOct,SUM(CASE WHEN Date1<'2008-10-1' THEN Amount END) AS AmountBeforeOct
FROM 表1
WHERE Date1<='2008-10-31'
select a.amount1,b.amount2
from (select sum(amount) amount1 from 表1 where Date1 between '2008-10-01' and '2008-10-31') as a,
(select sum(amount) amount2 from 表1 where Date1<'2008-10-01') as b
很简单,如下:
select sum(case when date1 <'2008/10/01' then amount else 0 end ) amount1,sum(case when date1 between '2008/10/01' and '2008/10/31' then amount else 0 end) amount2 from 表1
select t1.a1 as a1 ,t2.a2 as a2 from
(select sum(amount) as a1 , 'K' as k from 表1 where date1 <='2008-10-01' ) t1,
(select sum(amount) as a2 , 'K' as k from 表1 where date1 >='2008-10-01' and date1 <='2008-10-31') t2
where
t1.k = t2.k