SELECT MasterOfDesign.masterOfSetCode, DesignOfSketching.designProductOfSampleCode, SUBSTRING(DesignOfSketching.designProductOfSampleCode, 7, 1) AS codeOfProduct,
DetailOfDesign.detailPageOfNo, DesignOfSketching.designModelOfNumber
FROM MasterOfDesign
LEFT JOIN DetailOfDesign on DetailOfDesign.detailMasterOfDesignId = MasterOfDesign.Id
LEFT JOIN DesignOfSketching on DesignOfSketching.designDetailOfDesignId = DetailOfDesign.Id
WHERE (MasterOfDesign.masterOfSetCode = 'PN161A' OR MasterOfDesign.masterOfSetCode = 'PN161B') AND SUBSTRING(DesignOfSketching.designProductOfSampleCode, 7, 1) = '2'
ORDER BY MasterOfDesign.masterOfSetCode ASC, DetailOfDesign.detailPageOfNo ASC, DesignOfSketching.designModelOfNumber ASC
จากโค๊ด ได้ผลลัพธ์ ดังนี้ครับ
แต่สิ่งที่ผมต้องการคือ ใช้ column name ที่ชื่อ detailPageOfNo ในเงื่อนไข WHERE ด้วย โดยสมมุติว่า detailPageOfNo = 3 และ masterOfSetCode = 'PN161A' AND masterOfSetCode = 'PN161B'
WHERE
(MasterOfDesign.masterOfSetCode in ('PN161A', 'PN161B')) AND
(
SUBSTRING(DesignOfSketching.designProductOfSampleCode, 7, 1) = '2'
or MasterOfDesign.detailPageOfNo=3
)
WHERE (MasterOfDesign.masterOfSetCode = 'PN161A' OR (MasterOfDesign.masterOfSetCode = 'PN161B' AND DetailOfDesign.detailPageOfNo <= 3))
AND SUBSTRING(DesignOfSketching.designProductOfSampleCode, 7, 1) = '2'