我想知道是否可以将 Mysql 查询的记录列出到自定义数组中,就像我做的那样
SELECT CAT.catgryname,count(JB.knifeid) AS total
FROM jbs AS JB
LEFT JOIN krgstrs AS KR ON KR.id = JB.knfid
LEFT JOIN accnts AS ACC ON ACC.job_id = JB.id
LEFT JOIN catgor AS CAT ON CAT.id = KR.subctid
WHERE JB.usrid =xxx
GROUP BY CAT.catgryname
它给了我
[0] => Array
(
[CAT] => Array
(
[categoryname] => Fridge Magnet
)
[0] => Array
(
[total] => 22
[MNTH] => Jan
)
)
我想为嵌套在里面的第二个数组使用自定义索引而不是 0
[0] => Array
(
[CAT] => Array
(
[categoryname] => Fridge Magnet
)
[DET] => Array
(
[total] => 22
[MNTH] => Jan
)
)
注意这里的 DET 而不是 0。
我试过
SELECT CAT.catname,count(cat.id) as DET.total
但它会引发错误,因为我认为它将 DET 解释为此处的表格。谢谢大家。