Postgre floor changes values postgresql

33 Views Asked by At

I have the following query

with debug as (
    select kode_toko_dbo 
    , kode_toko_final
    , nama_toko_final
    , concat (point_category,' - ',point) poin_kategori
    , point
    , sum(total_do_qty) total_do_qty
    , sum(case when upper(replace(item_name,' ','')) ~ upper('^.*Classic.*(6|8)') then floor(total_do_qty::numeric /10)
        when upper(kategori_name_l1) = 'RB FASCIA' then (floor(total_do_qty::numeric /10))
        when upper(replace(item_name,' ','')) ~  upper('^.*Classic.*(3|4)\.5') then floor(total_do_qty::numeric /10)
        else 0 end) reward_toko
    from outputnya 
    group by 1,2,3,4,5
    --order by reward_toko desc 
    )
    select kode_toko_dbo 
    , kode_toko_final 
    , nama_toko_final 
    , poin_kategori
    , point
    , total_do_qty
    , reward_toko   
    from debug
    where kode_toko_final  in ('2012000044','2012000044')
    order by reward_toko desc 

it gives the the following results: enter image description here

When we devide 8417 with 10, it returns 841 which is correct.

When we divide 2950 with 10, it returns 293 which is wrong. It shud returns 295.

How do i resolve this?

when i tried the following query:

select 2950
, floor(2950::numeric / 10)
, floor(2950::numeric / 10) * 4 
limit 5 

it gives me the correct results.

enter image description here

How do i resolve this?

0

There are 0 best solutions below