gpt4 book ai didi

mysql - 如何将查询从 sql 转换为 codeigniter

转载 作者:行者123 更新时间:2023-11-29 16:14:52 25 4
gpt4 key购买 nike

这是我需要从 SQL 转换为 CodeIgniter 的查询:

SELECT b.bulan_tahun,b.kec, SUM(b.LFormal) AS LFormal, SUM(b.PFormal) AS PFormal, SUM(b.LFormal)+SUM(b.PFormal) AS SUMFormal,
SUM(b.LInformal) AS LInformal, SUM(b.PInformal) AS PInformal, SUM(b.LInformal)+SUM(b.PInformal) AS SUMInformal, SUM(b.LFormal)+ SUM(b.LInformal) AS LJumlah,
SUM(b.PFormal)+SUM(b.PInformal) AS PJumlah,SUM(b.LFormal)+SUM(b.LInformal)+SUM(b.PFormal)+SUM(b.PInformal) AS SUMJUMLAH FROM
(SELECT a.bulan_tahun,a.kec,
(CASE WHEN a.sktor_pkrjaan='FORMAL' AND a.jk='L' THEN JJK ELSE 0 END) AS LFormal,
(CASE WHEN a.sktor_pkrjaan='FORMAL' AND a.jk='P' THEN JJK ELSE 0 END) AS PFormal,
(CASE WHEN a.sktor_pkrjaan='INFORMAL' AND a.jk='L' THEN JJK ELSE 0 END) AS LInformal,
(CASE WHEN a.sktor_pkrjaan='INFORMAL' AND a.jk='P' THEN JJK ELSE 0 END) AS PInformal
FROM
(SELECT id_tki,bulan_tahun,kec, COUNT(jk) AS JJK, sktor_pkrjaan, jk
FROM tki
GROUP BY id_tki,bulan_tahun,kec, sktor_pkrjaan, jk) a
WHERE a.JJK>0) b
GROUP BY b.bulan_tahun,b.kec

我尝试在 Active Record CodeIgniter 上搜索,但未能得到答案。

谢谢。

最佳答案

像这样

$sql = "your query here";
$this->db->query($sql)->result();

关于mysql - 如何将查询从 sql 转换为 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54919466/

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