将Sql查询转换为Sql CodeIgniter



将sql查询转换为sql代码点火器我确实试过用这种方法如何将sql查询转换为代码点火器活动记录但不是为我工作。。。所以我试着在这里张贴

这是我的sql查询

$sql = "SELECT b.id, b.us_id, b.kredit, b.info,u.us_name, 
u.us_username, u.us_email, u.us_phone, b.cnt, b.amnt 
FROM users u JOIN
(SELECT id, us_id, kredit, info, COUNT(info) cnt, SUM(kredit) amnt 
FROM balance_history 
GROUP BY info HAVING cnt > 1
) AS b 
ON u.us_id = b.us_id 
WHERE b.kredit != '0' AND 
b.info NOT LIKE '[PERBAIKAN]%' AND 
(b.info LIKE 'Transfer saldo%' OR b.info LIKE 'Ket%') 
ORDER BY b.id ASC";

谢谢。。。

如果您没有全局加载数据库,您可以通过调用$this->load->database();来加载它。下面的查询可能提供相同的数据库调用。

$this->db->select('id, us_id, kredit, info, COUNT(info) cnt, SUM(kredit) amnt')
->from('balance_history')
->group_by('info')
->having('cnt > 1');
$subquery = $this->db->get_compiled_select();
$query  =   $this->db
->select('b.id, b.us_id, b.kredit, b.info,u.us_name,u.us_username, u.us_email, u.us_phone, b.cnt, b.amnt')
->from('users u')
->join('('.$subquery.') b','u.us_id = b.us_id')
->where('b.kredit !=','0', true)
->not_like('b.info', '[PERBAIKAN]', 'after', false, true)
->where('(b.info LIKE "Transfer saldo%" OR b.info LIKE "Ket%")')
->get();

相关内容

  • 没有找到相关文章

最新更新