CodeIgniter嵌套查询问题

时间:2013-11-21 12:23:40

标签: php codeigniter activerecord oracle11g

我试图将下面的代码转换为codeigniter活动记录而没有任何成功。我在这里搜索了任何相关的问题,但我在这里找到的codeigniter active record nested query不适合我。

下面是sql我试图转换

SELECT "BCB_ID","BCB_COST_CENTRE_NUMBER","BCB_TRANSFER_DATE","BCB_ARRIVAL_SEQUENCE","BCB_LOCATION_TYPE", "BCB_REFERENCE",
SUM(cfb) as CFB, SUM(ctb) as CTB, SUM(cts) as CTS, SUM(cfs) as CFS 
FROM(SELECT "BCB_ID","BCB_COST_CENTRE_NUMBER", "BCB_DATE", "BCB_ARRIVAL_SEQUENCE","BCB_LOCATION_TYPE", "BCB_TRANSFER_DATE", "BCB_REFERENCE", "BCB_SOURCE", 
    SUM(BCB_CASH_FROM_BANK )as CFB, SUM(BCB_CASH_TO_BANK ) as CTB, SUM(BCB_CASH_TO_SHOPS )as CTS, SUM(BCB_CASH_FROM_SHOPS ) as CFS
    FROM "WHOUSE1"."DLY_BWR_CASH_AND_BANKING"
    WHERE "BCB_COST_CENTRE_NUMBER" =  '1222'
    AND "BCB_TRANSFER_DATE" >= 20130130
    and bcb_source in ('A','C')
    GROUP BY "BCB_ID","BCB_COST_CENTRE_NUMBER", "BCB_DATE", "BCB_ARRIVAL_SEQUENCE", "BCB_LOCATION_TYPE", "BCB_TRANSFER_DATE", "BCB_REFERENCE", "BCB_SOURCE"
    ORDER BY "BCB_TRANSFER_DATE" DESC
    )
GROUP BY  "BCB_ID", "BCB_COST_CENTRE_NUMBER",  "BCB_TRANSFER_DATE", "BCB_ARRIVAL_SEQUENCE", "BCB_LOCATION_TYPE", "BCB_REFERENCE"
ORDER BY  "BCB_TRANSFER_DATE" DESC

任何帮助都将受到赞赏。感谢

1 个答案:

答案 0 :(得分:0)

$this->db->query("SELECT "BCB_ID","BCB_COST_CENTRE_NUMBER","BCB_TRANSFER_DATE","BCB_ARRIVAL_SEQUENCE","BCB_LOCATION_TYPE", "BCB_REFERENCE",
SUM(cfb) as CFB, SUM(ctb) as CTB, SUM(cts) as CTS, SUM(cfs) as CFS 
FROM(SELECT "BCB_ID","BCB_COST_CENTRE_NUMBER", "BCB_DATE", "BCB_ARRIVAL_SEQUENCE","BCB_LOCATION_TYPE", "BCB_TRANSFER_DATE", "BCB_REFERENCE", "BCB_SOURCE", 
    SUM(BCB_CASH_FROM_BANK )as CFB, SUM(BCB_CASH_TO_BANK ) as CTB, SUM(BCB_CASH_TO_SHOPS )as CTS, SUM(BCB_CASH_FROM_SHOPS ) as CFS
    FROM "WHOUSE1"."DLY_BWR_CASH_AND_BANKING"
    WHERE "BCB_COST_CENTRE_NUMBER" =  '1222'
    AND "BCB_TRANSFER_DATE" >= 20130130
    and bcb_source in ('A','C')
    GROUP BY "BCB_ID","BCB_COST_CENTRE_NUMBER", "BCB_DATE", "BCB_ARRIVAL_SEQUENCE", "BCB_LOCATION_TYPE", "BCB_TRANSFER_DATE", "BCB_REFERENCE", "BCB_SOURCE"
    ORDER BY "BCB_TRANSFER_DATE" DESC
    )
GROUP BY  "BCB_ID", "BCB_COST_CENTRE_NUMBER",  "BCB_TRANSFER_DATE", "BCB_ARRIVAL_SEQUENCE", "BCB_LOCATION_TYPE", "BCB_REFERENCE"
ORDER BY  "BCB_TRANSFER_DATE" DESC");////TRY THIS CODE

---以及此指南的链接http://ellislab.com/codeigniter/user-guide/database/results.html