sql - How to join a number with the range of number from another table -


   id   |  count ----------------- 1       |   45  2       |   5  3       |  120  4       |  87  5       |  60  6       |  200   7       | 31  sizename | lowerlimit | upperlimit --------------------------------- small    | 0          |  49  medium   | 50         |  99  large    | 100        |  250 

basically, 1 table specifies unknown number of "range names" , integer ranges associated. count range of 0 49 person table gets 'small' designation. 50-99 gets 'medium' etc. need dynamic because not know range names or integer values. can in single query or have write separate function loop through possibilities?

one way join tables, depending on if want keep values outside of "range names", or not, use left, or inner join respectively.

select a.id, a.count, b.sizename tablea left join tableb b on a.id >= b.lowerlimit , a.id < b.upperlimit 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -