有人能帮助我如何生成这个查询到Cakephp查询生成器.我正在升级我的2.x项目到4.x,
SELECT
Saving.id,
SUM(IFNULL(Saving.interest,0)) + SUM(IFNULL(CASE SavingSub.type when '1' AND SavingSub.interest <= 0 then SavingSub.amount else 0 end,0)) + SUM(IFNULL(CASE SavingSub.type when '1' AND SavingSub.interest > 0 then SavingSub.interest else 0 end,0)) - SUM(IFNULL(CASE SavingSub.type when '0' then SavingSub.amount else 0 end,0)) - SUM(IFNULL(Saving.interest,0)) as total
FROM
savings as Saving
left join saving_subs as SavingSub On SavingSub.saving_id = Saving.id
where
Saving.visible = true and
SavingSub.visible = true
group by
Saving.id
1条答案
按热度按时间q1qsirdb1#
我是如何做到的(不确定这是否是最好的解决方案,如果它在你的情况下工作):
如果你的查询中没有变量,你可以只保留:id和array ['id' =〉$id]。