мне показалось проще выдернуть, чем понять логику :-D
Код:
select s.closedate as дата, s.name as магазин, s.desknum as касса, s.znum as Z, sum(s.summa) as сумма, o.name as операция, g.title as ставка, replace(replace(to_char(s.bn),'1','безнал'),'0','нал') as платеж, s.opcode as o, s.taxgroupid as t
from saoperation o,
smtaxgroupdef g,
(select sum(i.totalsum) as summa, h.opcode, t.taxgroupid, h.locid, h.desknum, h.znum, h.checknum, nvl(sign(sum(b.totalsum)),0) as bn, z.closedate, l.name
from smcashz z,
smcashcheckitems i
left join smcashcredcardchecks b on b.locid=i.locid and b.desknum=i.desknum and b.znum=i.znum and b.checknum=i.checknum,
smcashchecks h,
smcardtax t,
smstorelocations l
where z.locid in (select id from smstorelocations where UPPER(name) like UPPER('%&Место_Хранения%'))
and z.closedate>=to_date('&Дата_Нач','DD.MM.YYYY')
and z.closedate<=to_date('&Дата_Кон','DD.MM.YYYY')
and h.locid=z.locid and h.desknum=z.desknum and h.znum=z.znum
and i.locid=h.locid and i.desknum=h.desknum and i.znum=h.znum and i.checknum=h.checknum
and t.article=i.article and t.datefrom<=z.closedate and t.dateto>=z.closedate
and l.id=z.locid
and t.rgnid=l.rgnid
group by h.opcode, t.taxgroupid, h.locid, h.desknum, h.znum, h.checknum, z.closedate, l.name) s
where o.id=s.opcode
and g.taxgroupid=s.taxgroupid
group by s.closedate, s.name, s.opcode, o.name, s.taxgroupid, s.bn, g.title, s.znum, s.desknum
order by s.closedate, s.desknum, s.znum ,s.opcode, s.bn, s.taxgroupid
у нас запускается из Query Reporter от Allround Automations когда те же самые цифирки не хочет давать укм4