mysql - 在 CodeIgniter 中将 MySQL 查询转换为 Active Record

标签 mysql codeigniter activerecord

我有这个 mysql 查询,而且我对 CodeIgniter 很陌生。如何将此 mysql 查询转换为 CodeIgniter 的 Active Record?

SELECT chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, 
chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment , MAX( chp_timestamp ) AS last_updated, MAX( chp_id )
FROM crm_hotel_price
LEFT JOIN crm_destinations ON cde_id = chp_destination
GROUP BY chp_destination, chp_year
ORDER BY chp_id

最佳答案

试试这个:(Reference)

$this->db->select('chp_destination, cde_name, chp_year, chp_from, chp_to, chp_budget_price_high, chp_medium_price_high, chp_luxury_price_high, chp_budget_price_low, chp_medium_price_low, chp_luxury_price_low, chp_timestamp, chp_comment, MAX(chp_timestamp) AS last_updated, MAX(chp_id)', FALSE);
$this->db->join('crm_destinations', 'cde_id = chp_destination', 'left');
$this->db->group_by('chp_destination, chp_year');
$this->db->order_by('chp_id');
$qry = $this->db->get('crm_hotel_price');
$res = $qry->result(); // or $qry->result_array();

关于mysql - 在 CodeIgniter 中将 MySQL 查询转换为 Active Record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18232994/

相关文章:

mysqli数据库表与codeigniter中的求和值连接

Mysql子查询返回多行,我需要插入选中的数据

mysql - 想知道 opened_tables!

php - 带有链接的 codeigniter View 中的回显计数行数

ruby-on-rails - 创建或更新 has_one ActiveRecord 关联

ruby-on-rails - 在 ActiveRecord 模型上使用建立连接时出现 AdapterNotSpecified

ruby-on-rails - Rails AR 日期范围查询 - 夏令时 - 重叠

php - 使用 PHP 从 MySQL Pivot 存储过程中选择

mysql - 检查 -lmysqlclient 中的 mysql_query() - ruby​​ gem mysql2 错误(Ubuntu 12.04 LTS)

php - Codeigniter 表单验证 - 如何在成功后取消设置表单值?