SqlReports
Changes
GetAverageCheck.sql 39(+30 -9)
Details
GetAverageCheck.sql 39(+30 -9)
diff --git a/GetAverageCheck.sql b/GetAverageCheck.sql
index 634e64f..3075ad7 100644
--- a/GetAverageCheck.sql
+++ b/GetAverageCheck.sql
@@ -32,9 +32,9 @@ begin
--declare @DateTo DateTime
--declare @ShopID int
---set @CompanyID = 1
---set @DateFrom = convert(DateTime, '15.04.2019', 104)
---set @DateTo = convert(DateTime, '21.04.2019', 104)
+set @CompanyID = 1
+set @DateFrom = convert(DateTime, '15.04.2019', 104)
+set @DateTo = convert(DateTime, '21.04.2019', 104)
declare @t1_RowCount int
declare @DateTo_Date DateTime
@@ -42,7 +42,7 @@ begin
set @DateTo = dateadd(ms, -2, dateadd(day, 1, @DateTo_Date))
- declare @t1 table (ShopID int index IX_t1_ShopID, Total decimal(15,2), ItemsCount int, CashCredit int, BankcardCredit int, MobileAppCredit int, ObedRuCredit int, CardNumber nvarchar(max))
+ declare @t1 table (ShopID int index IX_t1_ShopID, Total decimal(15,2), ItemsCount int, CashCredit int, BankcardCredit int, MobileAppCredit int, ObedRuCredit int, YandexRuCredit int, CardNumber nvarchar(max))
insert into @t1
select
@@ -53,6 +53,7 @@ begin
ss.BankcardCredit,
ss.MobileAppCredit,
sc.Value as ObedRuCredit,
+ scy.Value as YandexRuCredit,
c.CardNumber
from dbo.Shops sh with (nolock)
@@ -67,13 +68,17 @@ begin
sl.TerminalId = t.Id
and sl.SessionId = ss.SessionId
+ left join dbo.Cards c on c.Id = ss.CardId
+
left join dbo.SessionCredits sc with (nolock) on
sc.TerminalId = t.Id
and sc.SessionId = ss.SessionId
and sc.Type = 5 -- ObedRu
- left join dbo.Cards c on c.Id = ss.CardId
-
+ left join dbo.SessionCredits scy with (nolock) on
+ scy.TerminalId = t.Id
+ and scy.SessionId = ss.SessionId
+ and scy.Type = 15 -- Yandex
where
sh.CompanyId = @CompanyID
@@ -87,6 +92,7 @@ begin
ss.BankcardCredit,
ss.MobileAppCredit,
sc.Value,
+ scy.Value,
c.CardNumber
set @t1_RowCount = (select count(*) from @t1)
@@ -102,7 +108,8 @@ begin
t.ByCashCount,
t.ByBankcardCount,
t.ByMobileAppCount,
- t.ByObedRuCount
+ t.ByObedRuCount,
+ t.ByYandexRuCount
from (
select
@@ -153,7 +160,14 @@ begin
when t1.ObedRuCredit > 0 then 1
else 0
end
- ) as ByObedRuCount
+ ) as ByObedRuCount,
+
+ Sum (
+ case
+ when t1.YandexRuCredit > 0 then 1
+ else 0
+ end
+ ) as ByYandexRuCount
from @t1 t1
@@ -214,7 +228,14 @@ begin
when t1.ObedRuCredit > 0 then 1
else 0
end
- ) as ByObedRuCount
+ ) as ByObedRuCount,
+
+ Sum (
+ case
+ when t1.YandexRuCredit > 0 then 1
+ else 0
+ end
+ ) as ByYandexRuCount
from @t1 t1
end
\ No newline at end of file