我需要将SQL查询转换为令人讨厌的对象树。
基本上我需要有这种树
[
id_record,
mSap,
process_rev,
process: [
{
mpProcess,
mpOrder,
bom: [
{
mbItem,
mbQuantity,
mbYield,
alt: [
{
maFatherItem,
maAltItem
}
]
}
]
}
]
]
这是我需要转换的查询结果in JSON format.。我想我可以在ES6 Javascript中做到这一点,但我需要使用Coldfusion。 我也可以阅读PHP,所以也许我可以将它转换为Coldfusion。 它太复杂了,我不知道如何制作它。
这是询问所有人的查询:
SELECT a.id_record, a.mSap,
b.process_rev, b.mpOrder, b.mpProcess, b.bom_rev, b.mbITem, b.mbQuantity, b.mbYield, b.maFatherItem, b.maAltItem
FROM tbl_model a
LEFT JOIN (
SELECT c.mpModel AS model, d.process_rev, c.mpOrder, c.mpProcess, e.bom_rev, e.mbItem, e.mbQuantity, e.mbYield, e.maFatherItem, e.maAltItem
FROM tbl_model_process c
INNER JOIN (
SELECT mrModel, MAX(mrRevision) AS process_rev
FROM tbl_model_revision
WHERE mrApproved = 2
AND mrType = 0
AND mrActive = 1
GROUP BY mrModel
) d
ON c.mpRevision = d.process_rev
AND c.mpModel = d.mrModel
LEFT JOIN (
SELECT f.mbModel, f.mbRevision AS bom_rev, f.mbProcess, f.mbItem, f.mbQuantity, f.mbYield, h.maFatherItem, h.maAltItem
FROM tbl_model_bom f
INNER JOIN (
SELECT mrModel, MAX(mrRevision) AS bom_rev
FROM tbl_model_revision
WHERE mrApproved = 2
AND mrType = 1
AND mrActive = 1
GROUP BY mrModel
) g
ON f.mbModel = g.mrModel
AND f.mbRevision = g.bom_rev
LEFT JOIN (
SELECT maModel, maProcess, maRevision, maFatherItem, maAltItem
FROM tbl_model_alt
) h
ON f.mbModel = h.maModel
AND f.mbProcess = h.maProcess
AND f.mbItem = h.maFatherItem
AND f.mbRevision = h.maRevision
) e
ON c.mpModel = e.mbModel
AND c.mpProcess = e.mbProcess
) b
ON b.model = a.id_record
WHERE a.mActive = 1
AND a.mSap IN (:models)
ORDER BY a.id_record, b.process_rev, b.mpOrder, b.mpProcess
答案 0 :(得分:2)
根据您使用的cf版本,按进程,bom,alt对查询进行分组,然后使用cfoutput或cf10 + loop的group属性并构建json输出。
答案 1 :(得分:0)
查询是否为ColdFusion变量?你能简单地把它发送到serializeJSON()吗?
viewWillDisappear