mysql - Checking if any of a list of values falls within a table of ranges -


i'm looking check whether of list of integers fall in list of ranges. ranges defined in table defined like:

#     type    field       default null    key  0           int(11) rangeid     0       no      pri  1           int(11) max         0       no      mul  2           int(11) min         0       no      mul  

using mysql 5.1 , perl 5.10.

i can check whether single value, 7, in of ranges statement like

select 1   range   7 between min , max 

if 7 in of ranges, single row back. if isn't, no rows returned.

now have list of, say, 50 of these values, not stored in table @ present. assemble them using map:

my $value_list = '('   . ( join ', ', map { int $_ } @values )   . ')'   ; 

i want see if of items in list fall inside of of ranges, not particularly concerned number nor range. i'd use syntax such as:

select 1   range   (1, 2, 3, 4, 5, 6, 7, 42, 309, 10000) between min , max 

mysql kindly chastises me such syntax:

operand should contain 1 column(s) 

i pinged #mysql quite helpful. however, having written time responded , thinking it'd helpful fix answer in more permanent medium, figured i'd post question anyhow. maybe provide different solution?

you can construct sql query in perl work multiple values follows:

sub check_range {     'select 1 range ' .         join ' or ' =>         map "($_ between min , max)" => @_ }  print check_range( 1, 2, 3, 4, 5, 6, 7, 42, 309, 10000 ), "\n";  > select 1 range (1 between min , max) or (2 between min , max) > or (3 between min , max) or (4 between min , max) ... 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -