postgresql query between

0

Table X has the following information:

(id serial unique, vlinicial numeric(10,2), vlfinal numeri(10,2))

ID VLINICIAL VLFINAL
--------------------
1   0.01     10000.00
2   10000.01 20000.00
3   20000.01 30000.00
4   30000.01 40000.00
5   40000.01 999999.00

My query to check which ID to choose:

select * from x where 17000.00 between vlinicial and vlfinal

The result should be ID 2 but it happens to give 0 lines ...

If you put a value below 10000.00 already ID 1 appears:

select * from x where 7000.00 between vlinicial and vlfinal

I tested it this way and it turned out, but did not query above no.

select id 
from
(select 1 as id, 0.01::numeric as vli, 10000.00::numeric as vlf
union all
select 2 as id, 10000.01::numeric as vli, 20000.00::numeric as vlf
union all
select 3 as id, 20000.01::numeric as vli, 30000.00::numeric as vlf
union all
select 4 as id, 30000.01::numeric as vli, 40000.00::numeric as vlf) as t1   
where 15000.00::numeric between t1.vli and t1.vlf

Any suggestions?

    
asked by anonymous 24.07.2018 / 22:35

0 answers