Friday, February 25, 2011

маркет плюс, средний чек

SELECT
SAREA.SAREANAME
--,Substring([SALESTIME],1,8) as [день]
--,Substring([SALESTIME],9,2) as [час]

--,[PACKNAME] as [фискалка]

,Sum(case [SALESREFUND] when 0 then [SALESSUM] else -1*[SALESSUM] end )/100 as [Сумма]
,Sum(case [SALESREFUND] when 0 then [SALESSUM] else -1*[SALESSUM] end )/100/Count([FRECNUM]) as [среднийчек]
,Count([FRECNUM]) as [чеков]



FROM [GuidForMP].[dbo].[SALES] [sales]
left join [GuidForMP].dbo.SAREA SAREA on SAREA.SAREAID=sales.SAREAID
where Substring([SALESTIME],1,6)='201101' and SALESTAG = 2 AND SALESCANC=0 AND sales.DELFLAG=0
group by SAREA.SAREANAME
--group by SAREA.SAREANAME,Substring([SALESTIME],1,8),Substring([SALESTIME],9,2),[PACKNAME]
--order by SAREA.SAREANAME,Substring([SALESTIME],1,8),Substring([SALESTIME],9,2),[PACKNAME]

No comments:

Post a Comment