我有一个名为折扣的表
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查询?
问候,
帕布
最佳答案
SELECT *
FROM discounts
WHERE 27 BETWEEN count_from AND count_to
SELECT *
FROM discounts
WHERE 33 BETWEEN count_from AND count_to
关于MySQL:在行列表中使用给定值找到合适的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339107/