CREATE VIEW znum30 AS SELECT DISTINCT FROM smcashchecks WHERE printtime > (SYSDATE - 30) ORDER BY znum;
CREATE VIEW code30 AS SELECT DISTINCT code FROM smcashdisccard WHERE znum IN (SELECT * FROM znum30) ORDER BY code;
UPDATE smdiscpers SET cardtype = 5 WHERE code NOT IN (SELECT * FROM code30);
DROP code30;
DROP znum30;
COMMIT;
SELECT (DCSUM.Code) as Field4,round((SUM((decode(Z.IsSale,'1',Z.TotalSum,0))-(decode(Z.IsSale,'1',0,Z.TotalSum)))),2) as Field3 FROM SVAnalyticsCheck Z,SVCashDiscCardSum DCSUM
WHERE Z.LocID=DCSUM.LocID(+) and Z.DeskNum=DCSUM.DeskNum(+) and Z.ZNum=DCSUM.ZNum(+) and Z.CheckNum=DCSUM.CheckNum(+) and Z.CheckDate between to_date('13.12.2016','DD.MM.YYYY') and to_date('11.01.2017','DD.MM.YYYY')
GROUP BY (DCSUM.Code) ORDER BY 1 ASC;
SELECT (DCSUM.Code) as Field4,round((SUM((decode(Z.IsSale,'1',Z.TotalSum,0))-(decode(Z.IsSale,'1',0,Z.TotalSum)))),2) as Field3 FROM SVAnalyticsCheck Z,SVCashDiscCardSum DCSUM
WHERE Z.LocID=DCSUM.LocID(+) and Z.DeskNum=DCSUM.DeskNum(+) and Z.ZNum=DCSUM.ZNum(+) and Z.CheckNum=DCSUM.CheckNum(+) and Z.CheckDate between to_date('13.12.2016','DD.MM.YYYY') and to_date('11.01.2017','DD.MM.YYYY')
GROUP BY (DCSUM.Code) ORDER BY 1 ASC;
SELECT (Code) as Field3 FROM SVAnalyticsCheck Z,SVCashDiscCardSum DCSUM WHERE Z.LocID=DCSUM.LocID(+) and Z.DeskNum=DCSUM.DeskNum(+) and Z.ZNum=DCSUM.ZNum(+) and Z.CheckNum=DCSUM.CheckNum(+) and Z.CheckDate between sysdate-30 and sysdate GROUP BY (DCSUM.Code) ORDER BY 1 ASC;