如何在mysql中选择开始日期和结束日期之间的折扣价值?

时间:2016-02-04 07:30:10

标签: php mysql

This is a snapshot of my table

我试过这个:

SELECT v.Discount FROM `product` AS v WHERE DATE(v.`start_date `) >= "2016-02-28" && DATE(v.`end_date`) <= "2016-02-28"

请帮助解决正确的问题。

2 个答案:

答案 0 :(得分:2)

您也可以通过BETWEEN功能执行此操作: -

SELECT v.Discount 
FROM 
product AS v 
WHERE 
'2016-02-28' BETWEEN v.start_date AND v.end_date;

答案 1 :(得分:1)

将数据库的日期格式与您发送的日期相匹配。 然后使用

SELECT v.Discount FROM product AS v WHERE v.start_date >= "2016-02-28" AND v.end_date <= "2016-02-28"

没有日期功能,因为您已在v.start_date以及v.end_date中拥有日期。

祝你好运!