gpt4 book ai didi

mysql - 从 MySQL 查询生成 CodeIgniter Active Record

转载 作者:行者123 更新时间:2023-11-29 00:27:34 25 4
gpt4 key购买 nike

我有这个 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

最佳答案

是的,事件记录尚不支持子查询,您无法轻松扩展该类。所以你想做这样的事情(未测试)

$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();

关于mysql - 从 MySQL 查询生成 CodeIgniter Active Record,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18250716/

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