SELECT calldate,src,substring(dst from '1#\"%#\"' for '#') as dst,CASE billsec % 6 WHEN 0 THEN ((( (billsec/6) *6)::float(1)/60)::float(1))::float(1) ELSE ((( ((billsec/6 +1)* 6))::float(1)/60)::float(1))::float(1)END as minutes,accountcode,(select rate from rates where lata = accountcode) as RATE, CASE billsec % 6 WHEN 0 THEN ((( (billsec/6) *6)::float(1)/60)::float(1) * (select rate from rates where lata = accountcode) )::float(1) ELSE ((( ((billsec/6 +1)* 6))::float(1)/60)::float(1)* (select rate from rates where lata = accountcode) )::float(1) END as amountFROM public.cdrWHERE calldate >= '11/01/2004' and calldate < '12/01/2004'and (src like '843%')and accountcode IN ('INTRA','INTER','ONNET')and lastdata <> ''and billsec > 0order by calldate