select cgicode from (select '1' sortflag,
pt.cgicode,
'1' cgcode,
pt.cgcode code,
c.gnamedesc,
pt.orderclass,
stockyear || '-' || stockmonth as instoredat,
0 qty,
sum(fcy * vdc) as fcy,
0 currtupric,
0 rtupric,
pt.affirmdate
vdc,
--pt.destccode,
pt.pricetype,
0 num
from priceadjust pt, cgcode c
where pt.cgicode = c.cgicode
and c.ccode = '4AE0'
and pt.fcode = 'RMB'
and vdc='-1'
and pt.pricetype='02'
and pt.cgcode = 'KFC0000004'
group by pt.cgicode,pt.cgcode,pt.orderclass,
stockyear, stockmonth,pricetype, vdc,c.gnamedesc,pt.affirmdate order by pt.cgicode
union all
select 'a' sortflag,
pl.cgicode,
--tradebody,
case
when pl.cgcode is null then
'合计'
when pl.cgcode is not null and pl.cgicode is null then
'小计'
else
'' || pl.cgcode
end cgcode,
pl.cgcode code,
gnamedesc,
orderclass,
stockyear || '-' || stockmonth as instoredat,
qty,
sum(fcy * vdc) as fcy,
currtupric,
rtupric,
affirmdate,
pricetype,
vdc,
-- adjustflags,
rownum num
from priceadjust pl, cgcode c
where pl.cgcode = c.cgcode
and c.ccode = '4AE0'
and pl.fcode = 'RMB'
and pl.cgicode = 'KFC0000004'
group by GROUPING SETS((pl.cgcode),(pl.cgcode, pl.cgicode, c.gnamedesc, pl.orderclass,
stockyear, stockmonth, qty, vdc, currtupric, rtupric, affirmdate, pricetype,vdc , rownum),())
) aa以上SQL语句说,缺少右括号,为什么啊
pt.cgicode,
'1' cgcode,
pt.cgcode code,
c.gnamedesc,
pt.orderclass,
stockyear || '-' || stockmonth as instoredat,
0 qty,
sum(fcy * vdc) as fcy,
0 currtupric,
0 rtupric,
pt.affirmdate
vdc,
--pt.destccode,
pt.pricetype,
0 num
from priceadjust pt, cgcode c
where pt.cgicode = c.cgicode
and c.ccode = '4AE0'
and pt.fcode = 'RMB'
and vdc='-1'
and pt.pricetype='02'
and pt.cgcode = 'KFC0000004'
group by pt.cgicode,pt.cgcode,pt.orderclass,
stockyear, stockmonth,pricetype, vdc,c.gnamedesc,pt.affirmdate order by pt.cgicode
union all
select 'a' sortflag,
pl.cgicode,
--tradebody,
case
when pl.cgcode is null then
'合计'
when pl.cgcode is not null and pl.cgicode is null then
'小计'
else
'' || pl.cgcode
end cgcode,
pl.cgcode code,
gnamedesc,
orderclass,
stockyear || '-' || stockmonth as instoredat,
qty,
sum(fcy * vdc) as fcy,
currtupric,
rtupric,
affirmdate,
pricetype,
vdc,
-- adjustflags,
rownum num
from priceadjust pl, cgcode c
where pl.cgcode = c.cgcode
and c.ccode = '4AE0'
and pl.fcode = 'RMB'
and pl.cgicode = 'KFC0000004'
group by GROUPING SETS((pl.cgcode),(pl.cgcode, pl.cgicode, c.gnamedesc, pl.orderclass,
stockyear, stockmonth, qty, vdc, currtupric, rtupric, affirmdate, pricetype,vdc , rownum),())
) aa以上SQL语句说,缺少右括号,为什么啊
要排序的话也要放到末尾
列数和类型都要匹配
按几种方式分组求sum(fcy * vdc),规则是怎么样的
能不能给个简单点的例子,我写个试试
组合零件出库的合计,再加上入库的明细,这两的小计(按cgcode:零件编码小计),让后总的零件的合计,就是这么一个sql文