php “大于或等于”和“小于或等于”代码点火器

zwghvu4y  于 2023-03-21  发布在  PHP
关注(0)|答案(5)|浏览(162)

我必须查询一些有where条件的东西,其中有>==<,但我没有运气。这是在CODEIGNITER中。
这是mysql查询的自然方式:

SELECT COUNT(payment.keyid) AS rec_count, `product_key`.`client_name`, 
`product_key`.`contact_email`, `product_key`.`status`, `product_key`.`id`, 
`payment`.`paymentdate`, (payment.id) as pid, `payment`.`subscription_type` 
FROM (`product_key`) 
LEFT OUTER JOIN `payment` ON `payment`.`keyid`=`product_key`.`id` 
WHERE `payment`.`paymentdate` >= '2013-08-01' 
    AND `payment`.`paymentdate` =< '2013-08-31' 
    AND `status` = 'purchased' 
GROUP BY `product_key`.`id` 
ORDER BY `client_name` asc

这是我的资料

return $this->db
    ->select('COUNT(payment.keyid) AS rec_count')
    ->select('product_key.client_name, product_key.contact_email, product_key.status, product_key.id, payment.paymentdate, (payment.id) as pid,payment.subscription_type')
    ->from('product_key')          
    ->where('payment.paymentdate >=', $month_start)
    ->where('payment.paymentdate =<', $month_end)
    ->where('status', 'purchased')
    ->join('payment', 'payment.keyid=product_key.id', 'left outer')
    ->order_by('client_name', "asc")
    ->group_by('product_key.id')
    ->get()
    ->result();

也许有人能帮我谢谢。

ee7vknir

ee7vknir1#

=<更改为<=
我还在phpmyadmin中测试了你当前的查询,因为我不相信它不会抛出错误。但是我的会。所以你的查询不应该在phpmyadmin中工作。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=< ...' at line ...
8yparm6h

8yparm6h2#

尝试将=<更改为<=,如下所示

->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)

better但不要在where条件之前连接表。

->select('COUNT(payment.keyid) AS rec_count')
->select('product_key.client_name, product_key.contact_email, product_key.status, product_key.id, payment.paymentdate, (payment.id) as pid,payment.subscription_type')
->from('product_key')         
->join('payment', 'payment.keyid=product_key.id', 'left outer')    
->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)
->where('status', 'purchased')
->order_by('client_name', "asc")
->group_by('product_key.id')
->get()
jum4pzuy

jum4pzuy3#

据我所知,你可以这样写

$this->db->select('COUNT(payment.keyid) AS rec_count, product_key.client_name, product_key.contact_email, product_key.status, product_key.id, payment.paymentdate, (payment.id) as pid, payment.subscription_type', false);
$this->db->where('payment.paymentdate >= "2013-08-01"');
$this->db->where('payment.paymentdate <= "2013-08-31"');
$this->db->where('status', 'purchased');
$this->db->group_by('product_key.id');
$this->db->order_by('client_name', 'asc');
$this->db->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
$this->db->get('product_key');
wbrvyc0a

wbrvyc0a4#

试试看:

$this->db
->select('COUNT(payment.keyid) AS rec_count, product_key.client_name, product_key.contact_email, product_key.status, product_key.id, payment.paymentdate, (payment.id) as pid, payment.subscription_type', false)
->from('product_key')
->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
->where('payment.paymentdate >=', '2013-08-01')
->where('payment.paymentdate <=', '2013-08-31')
->where('status', 'purchased')
->group_by('product_key.id')
->order_by('client_name', 'asc')
->get();
um6iljoc

um6iljoc5#

$this->db->where("DATE_FORMAT(ph_payment_date, '%d-%m-%Y') BETWEEN '$startdate' AND '$enddate'");
$this->db->where("DATE_FORMAT(ph_payment_date, '%d-%m-%Y') >= '$startdate'");
$this->db->where("DATE_FORMAT(ph_payment_date, '%d-%m-%Y') <= '$enddate'");

相关问题