我有这个问题。
$data['incomes'] = $this->db->query("SELECT SUM(payment) as total_income FROM drivers_statement where datetime LIKE '$today%' && pay_method = 'cash'")->result();
我想将其更改为
$data['incomes'] = $this->db->query("SELECT SUM(payment) as total_income FROM drivers_statement where datetime >= LIKE '$first%' AND datetime <= LIKE '$today%' && pay_method = 'cash'")->result();
如何同时使用更大和LIKE?
答案 0 :(得分:1)
如何同时使用更大和LIKE?
使用逻辑运算符检查两者是否&gt; (更大)和'LIKE'同时成立,如下:
WHERE x > y AND x LIKE y
所以我想像是
$data['incomes'] = $this->db->query("SELECT SUM(payment) as total_income FROM drivers_statement where datetime >= '$first%' AND datetime LIKE '$first%' AND datetime <= '$today%' AND datetime LIKE '$today%' && pay_method = 'cash'")->result();
会做的。
请注意我是伪编码,并没有尝试通过阅读您的查询来了解您的目标,我不知道这是否有效。基本上我通过告诉你使用这种模式回答了“如何使用通用运算符和另一个运算符”的问题:
WHERE (x OP1 y) AND (x OP2 y)
其中OP1>或者&gt; =和OP2是LIKE,在你的情况下。
答案 1 :(得分:0)
我用它实现了它。
$today = date("Y-m-d h:i:s");
$first = $first.' 00:00:00';
$data['incomes'] = $this->db->query("SELECT payment FROM drivers_statement where datetime >= '$first' AND datetime <= '$today' && pay_method = 'cash'")->result();