SQL query for finding a value in multiple ranges

后端 未结 2 2049
梦如初夏
梦如初夏 2020-12-22 09:45

i have MySQL db that contains event\'s date and 3 ranges, i.e from1-to1, from2-to2, from3-to3
each range has different price, i.e from1-to1 rate1 , from2-to2 rate2, ...

2条回答
  •  甜味超标
    2020-12-22 10:23

    If you make an extra table just for the ranges you would keep your schema in normal form and you could easy select the right rate: TABLE range, COLUMNS from, to, rate. With a foreign key linking to your original table. Then you could SELECT rate FROM range WHERE 'date' >= from AND 'date' <= to.

提交回复
热议问题