1

我有一张表叫打折

Field        Type 
id           int(11) NOT NULL
resort_id    int(11) NOT NULL
count_from   int(11) NULL
count_to     int(11) NULL
discount     varchar(255) NULL

我有如下行:

 
  id |product_id |count_from |count_to |discount
    1|8 |0 |30 |22
    2|8 |31 |60 |12
  

当我得到 27 作为输入时,我应该检索第一行(id:1)。假设如果我的输入是 33,我应该检索 2 行(id:2)。

如何编写一个mysql查询?

问候,
帕布

4

1 回答 1

4
SELECT *
FROM discounts
WHERE 27 BETWEEN count_from AND count_to

SELECT *
FROM discounts
WHERE 33 BETWEEN count_from AND count_to
于 2012-04-26T18:22:47.900 回答