我想根据今天的日期选择行,包括开始日期和到期日期列,甚至是没有日期值的行。所以
$query=mysql_query("SELECT * FROM discounts where '".date('Y-m-d')."' >= coupon_start_date AND '".date('Y-m-d')."' <= coupon_expiry_date
UNION SELECT * FROM ecwid_discounts where '".date('Y-m-d')."' >= coupon_start_date AND coupon_expiry_date is NULL union SELECT * FROM ecwid_discounts where coupon_start_date is NULL AND '".date('Y-m-d')."' <= coupon_expiry_date union SELECT * FROM ecwid_discounts where coupon_start_date is NULL AND coupon_expiry_date is null");
我想确认此查询是否正确,或者是否有更好的方法可以简单地重写此查询。
任何帮助人员
答案 0 :(得分:0)
使用此查询:
$query=mysql_query("SELECT * FROM discounts where '".date('Y-m-d')."' >= coupon_start_date AND '".date('Y-m-d')."' <= coupon_expiry_date
UNION SELECT * FROM ecwid_discounts where '".date('Y-m-d')."' >= coupon_start_date AND '".date('Y-m-d')."' <= coupon_expiry_date OR '".date('Y-m-d')."' >= coupon_start_date AND coupon_expiry_date is NULL OR coupon_start_date is NULL AND '".date('Y-m-d')."' <= coupon_expiry_date OR coupon_start_date is NULL AND coupon_expiry_date is null");