我試圖在鏈接到位置編號(1到6)的單個列中返回多個值,但只是在每種情況下都具有特定位置的那些值。基本上我有6個我想創建的列,每個位置1個,並返回與該位置編號關聯的所有結果值。我創建了6個巢式病例報告,試圖獲得這些結果:從SELECT中返回嵌套在CASE中的多個值
(CASE WHEN tbl_TestWells.well_result <> NULL
THEN
(SELECT tbl_TestWells.well_result
FROM tbl_TestWells
WHERE tbl_TestWells.Well_Index = 1)
ELSE NULL END) AS Well_1_Graded_Result,
的問題是,他們只在它的設置方式返回NULL值。如果我把這個情況拿出來,那麼我得到錯誤消息「subquery返回的值超過1,當子查詢跟隨=,!=,<,< =,>,> =或者子查詢用作表達。」
編輯:完整的代碼部分的圖,所以我已經將其簡化成什麼相關
SELECT DISTINCT
--Other Columns being selected
(CASE WHEN tbl_TestWells.well_result <> NULL
THEN
(SELECT tbl_TestWells.well_result
FROM tbl_TestWells
WHERE tbl_TestWells.Well_Index = 1)
ELSE NULL END) AS Well_1_Graded_Result,
--The other five well results are set up in the exact same format as above, just replacing 1 with the corresponding number
FROM tbl_TestCartridges
JOIN tbl_Tests ON
tbl_Tests.test_uid = tbl_TestCartridges.test_uid
JOIN tbl_Programs ON
tbl_Programs.program_uid = tbl_Tests.program_uid
JOIN tbl_Cartridges ON
tbl_Cartridges.system_uid = tbl_Programs.system_uid
JOIN tbl_TestWells ON
tbl_TestWells.test_cartridge_uid = tbl_TestCartridges.test_cartridge_uid
JOIN tbl_TestSamples ON
tbl_TestSamples.test_well_uid = tbl_TestWells.test_well_uid
ORDER BY tbl_TestCartridges.barcode
;
可能有助於特別注意什麼,你正在使用SQL(T-SQL,MySQL和PL/SQL)的變種,因爲ISNULL/IFNULL它們的功能各不相同。 –