我有这个mysql查询,我是CodeIgniter的新手,我怎样才能将它作为一个有效的记录查询?
SELECT
chp_id,
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
FROM crm_hotel_price
LEFT JOIN crm_destinations ON cde_id = chp_destination
WHERE chp_id IN
(
SELECT MAX( chp_id )
FROM crm_hotel_price
GROUP BY chp_destination, chp_year
)
ORDER BY
chp_id
答案 0 :(得分:1)
是活动记录尚不支持子查询,您无法轻松扩展该类。所以你想做这样的事情(未经测试)
$this->db->select('chp_id')
->select('chp_destination')
->select('cde_name')
->select('chp_year')
->select('chp_from')
->select('chp_to')
->select('chp_budget_price_high')
->select('chp_medium_price_high')
->select('chp_luxury_price_high')
->select('chp_budget_price_low')
->select('chp_medium_price_low')
->select('chp_luxury_price_low')
->select('chp_timestamp')
->select('chp_comment')
->from('crm_hotel_price')
->join('crm_destinations', 'cde_id = chp_destination', 'left')
->where('chp_id IN (SELECT MAX( chp_id ) FROM crm_hotel_price GROUP BY chp_destination, chp_year)')
->order_by('chp_id');
$query = $this->db->get();