2012-04-26 38 views
1

找到合適的行我呼籲折扣MySQL的:行列表使用給定值

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
SELECT * 
FROM discounts 
WHERE 27 BETWEEN count_from AND count_to 

SELECT * 
FROM discounts 
WHERE 33 BETWEEN count_from AND count_to 
+0

太感謝你了..這是工作。 – Prabu 2012-04-26 18:26:08

相關問題