gpt4 book ai didi

mysql - 如何将sql查询转换为codeigniter事件记录

转载 作者:行者123 更新时间:2023-11-29 17:58:03 24 4
gpt4 key购买 nike

如何将sql查询转换为codeigniter事件记录

查询:

 SELECT s2.hierarchy_users_id, 
s2.commisions,
s1.given_amount
FROM (SELECT hierarchy_users_id,
Sum(commisions) AS commisions
FROM commision
GROUP BY hierarchy_users_id = '2') AS s2
LEFT OUTER JOIN(SELECT hierarchy_users_id,
Sum(given_amount)AS given_amount
FROM incentives
GROUP BY hierarchy_users_id = '2')AS s1
ON s1.hierarchy_users_id = s2.hierarchy_users_id
LIMIT 1

最佳答案

您可以尝试此 codeignitor 事件记录查询。

查询:-

$this->db->select('s2.hierarchy_users_id, s2.commisions, s1.given_amount ',false);
$this->db->from('SELECT hierarchy_users_id, Sum(commisions) AS commisions FROM commision WHERE hierarchy_users_id = "'.$ids[$o].'" GROUP BY hierarchy_users_id) AS s2');
$this->db->join('SELECT hierarchy_users_id, Sum(given_amount)AS given_amount FROM incentives WHERE hierarchy_users_id = "'.$ids[$o].'" GROUP BY hierarchy_users_id) AS s1','s1.hierarchy_users_id = s2.hierarchy_users_id','left outer');
$this->db->limit('1');
$query_result = $this->db->get();
$result = $query_result->result();
return !empty($result) ? $result : '';

或者

$this->db->select('s2.hierarchy_users_id, s2.commisions, s1.given_amount ',false);
$this->db->from('SELECT hierarchy_users_id, Sum(commisions) AS commisions FROM commision GROUP BY hierarchy_users_id) AS s2');
$this->db->join('SELECT hierarchy_users_id, Sum(given_amount)AS given_amount FROM incentives GROUP BY hierarchy_users_id) AS s1','s1.hierarchy_users_id = s2.hierarchy_users_id','left outer');
$this->db->limit('1');
$query_result = $this->db->get();
$result = $query_result->result();
return !empty($result) ? $result : '';

您可以尝试使用第一个选项(hierarchy_users_id = "2"),否则尝试第二个选项(所有hierarchy_users_id)

希望对您有所帮助。

关于mysql - 如何将sql查询转换为codeigniter事件记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48640312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com