【发布时间】:2019-11-23 11:18:45
【问题描述】:
是否可以在 Yii2 中将这种 SQL 转换为 ActiveRecord 查询:
SELECT a.id,
case length(a.id)
when 6 then (select region_name from region where id = concat(left(a.id,2),'0000'))
when 5 then (select region_name from region where id = concat(left(a.id,1),'0000'))
end as prov,
case length(a.id)
when 6 then (select region_name from region where id = concat(left(a.id,4),'00'))
when 5 then (select region_name from region where id = concat(left(a.id,3),'00'))
end as kab,
(select region_name from region where id = a.id) as kec
FROM region as a
WHERE a.region_name LIKE '%kamb%'
【问题讨论】:
标签: yii2