“大于或等于”和“小于或等于”共同标志

2022-08-30 23:22:18

我必须查询具有 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(); 

也许有人可以帮助我。谢谢。


答案 1

更改为 。=<<=

我还在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 ...

答案 2

尝试将 更改为“喜欢”=<<=

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

最好但不合计数,在位置条件之前加入表。现在你的查询应该像这样

->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()

推荐