我得到了一个非常复杂的查询(至少对我而言)。 我想创建一个准备好付费的用户列表。有两个条件需要满足:订单状态应该是3,总数应该超过50.目前我得到了这个查询(使用Codeingiter活动记录生成):
SELECT `services_payments`.`consultant_id`
, `consultant_userdata`.`iban`
, `consultant_userdata`.`kvk`, `consultant_userdata`.`bic`
, `consultant_userdata`.`bankname`
, SUM(`services_payments`.`amount`) AS amount
FROM (`services_payments`)
JOIN `consultant_userdata`
ON `consultant_userdata`.`user_id` = `services_payments`.`consultant_id`
JOIN `services`
ON `services`.`id` = `services_payments`.`service_id`
WHERE `services`.`status` = 3
AND `services_payments`.`paid` = 0
HAVING `amount` > 50
services_payments表包含佣金,consultant_userdata包含userdata和services保存订单数据。当前查询只给出了1个结果,而我期待4个结果。
有人可以告诉我我做错了什么以及解决方案是什么?
答案 0 :(得分:1)
对于ActiveRecord,rsanchez的答案更多是
$this->db->group_by('services_payments.consultant_id, consultant_userdata.iban, consultant_userdata.kvk, consultant_userdata.bic, consultant_userdata.bankname');