我希望将以下三个查询合并为一个查询,并将总数输出到3列中。哦,如何使它不必声明日期。我希望它能“知道”当前的日期、月份和年份。
DECLARE @myDate as datetime
SET @myDate = '2015-01-1'
select SUM(Amount) as 'Day Total'
from [Accounting].[dbo].[HandPay]
where AccountingDate>=@myDate and AccountingDate<dateadd(day,1,@myDate)
select SUM(Amount) as 'Month Total'
from [Accounting].[dbo].[HandPay]
where AccountingDate>=@myDate and AccountingDate<dateadd(MONTH,1,@myDate)
select SUM(Amount) as 'Day Total'
from [Accounting].[dbo].[HandPay]
where AccountingDate>=@myDate and AccountingDate<dateadd(year,1,@myDate)
什么是最佳实践?感谢所有超快的反应!问题已经解决。