从指定的特定日期中选择所有销售

I have a coupon and would like to get all the rows that used a promo code after the creation date.

Each sale is timestamped and the coupon created is time stamped. Id like to select all the sales that are made after the coupon day.

Heres what I have.

$coupon = $this->db->query("SELECT * FROM group_coupon WHERE code='test' AND active='1'");


if (count($coupon) > 0) {


  $amount = $this->db->query("SELECT * FROM group_coupon WHERE code='test'")->row()->amount;

  $quantity = $coupon->row()->quantity;
    echo "Quantity: " . $quantity;

echo "Time: " . $coupon->row()->timestamp;

// I know the query is wrong 
$time_st = $coupon->row()->timestamp;
   $all = $this->db->query("SELECT * FROM sale WHERE coupon='test' AND $time_st > timestamp")->row()->coupon;

// then id like to do a count($all) 

}

You've made a bit of a logic error.

Let's say that the coupon you're checking was made at 1 pm and that time is represented by the number 100 (which is $time_st in this case). Then, there's another coupon made one hour after at 2 pm, represented by 200 (timestamp). You then check if $time_st > timestamp and this evaluates to 100 > 200 and this is not true.

What you want to do is check if the timestamp of the coupon you're checking is less than the other timestamps, so you know that they were made in the future.

Your query should be:

$all = $this->db->query("SELECT * FROM sale WHERE coupon='test' AND $time_st < timestamp")->row()->coupon;