SELECT image_id,
CASE image_id
WHEN 0 THEN (SELECT image_path
FROM images
WHERE image_id IN (SELECT default_image
FROM registration
WHERE reg_id IN (SELECT favorite_id
FROM @favDT)))
ELSE (SELECT image_path
FROM images
WHERE image_id = b.image_id
AND active = 1)
END AS image_path
FROM buddies b
WHERE reg_id IN (SELECT favorite_id
FROM @favDT)
我在这个查询中遇到了一个问题,因为select favorite_id from @favDT
在这种情况下返回了许多最喜欢的 id,但我需要获取在 from 部分中选择的相同的最喜欢的 idFROM buddies b where reg_id in (select favorite_id from @favDT)
并使用它case when 0
有什么帮助吗?