如果你正在使用MySQL,你可以使用GROUP BY
和GROUP_CONCAT
所有TOAL
值如:
SELECT jobcard.code AS code1,jobcard.name AS name1, GROUP_CONCAT(NVL(masterpm.id,0)) AS toal
FROM jobcard LEFT JOIN masterpm ON jobcard.id = masterpm.jobcard_id AND masterpm.id in (SELECT masterpm_id FROM cbmmasterpm)
GROUP BY code1, name1;
Here's關於GROUP_CONCAT
的MySQL文檔。
更新
當你使用的是Oracle,你可以使用listagg
函數來實現相同的功能,例如:
SELECT jobcard.code AS code1, jobcard.name AS name1,
LISTAGG(NVL(masterpm.id,0), ', ') WITHIN GROUP (ORDER BY masterpm.id) "TOAL"
FROM jobcard LEFT JOIN masterpm ON jobcard.id = masterpm.jobcard_id AND masterpm.id in (SELECT masterpm_id FROM cbmmasterpm)
GROUP BY code1, name1;
Here's的文檔。
我刪除了不兼容的數據庫標記。 –
@GordonLinoff謝謝:) – saman
請閱讀http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557和接受的答案 –