34,590
社区成员
发帖
与我相关
我的任务
分享
declare @st datetime
declare @et datetime
declare @sh int
set @st=cast('2009-1-1' as datetime)
set @et=cast('2009-12-31' as datetime)
select (max(txhour)-min(txhour)) as hh into #tmp from dbo.cathm where txdate between @st and @et group by txdate
select @sh=sum(hh) from #tmp
drop table #tmp
select sum(amt)*1.00/@sh,sum(qty)*1.00/@sh
from cathm
where txdate between @st and @et
select sum(amt)/datediff(dd,@st,@et),sum(qty)/datediff(dd,@st,@et)from dbo.cathm
where txdate between @st and @et and txhour>=22 '一般情况营业时间到晚22:30点