Select dc.Code,ss.sumsale FROM supermag.smdiscpers dc, (select code, sum(sumsale) as sumsale from supermag.smactivityclient group by code) ss where (dc.code=ss.code)
UPDATE supermag.smdiscpers SET cardtype=SELECT ID FROM SMDiscType where id=8 WHERE code=:cardcode
UPDATE supermag.smdiscpers SET cardtype=8 WHERE code in (Select dc.Code FROM supermag.smdiscpers dc, (select code, sum(sumsale) as sumsale from supermag.smactivityclient group by code) ss where (dc.code=ss.code) and (ss.sumsale>=:Mysum1 and ss.sumsale<:Mysum2 )