CASE WHEN THEN

SELECT
(CASE
WHEN News_Data.Type = 1 THEN (SELECT Sys_Department.Name FROM Sys_Department WHERE Sys_Department.Id = News_Data.ObjectId)
WHEN News_Data.Type = 2 THEN (SELECT Basic_Community.Name FROM Basic_Community WHERE Basic_Community.Id = News_Data.ObjectId)
WHEN News_Data.Type = 3 THEN (SELECT Basic_Property.Name FROM Basic_Property WHERE Basic_Property.Id = News_Data.ObjectId)
WHEN News_Data.Type = 4 AND ObjectId != '00000000-0000-0000-0000-000000000000' THEN (SELECT Basic_HousingEstate.Name FROM Basic_HousingEstate WHERE Basic_HousingEstate.Id = News_Data.ObjectId)
WHEN News_Data.Type = 4 AND ObjectId = '00000000-0000-0000-0000-000000000000' THEN ''
ELSE ''
END
)ObjectName,*
FROM News_Data WHERE State= 1

上一篇:使用Spring访问Mongodb的方法大全——Spring Data MongoDB


下一篇:Spring Boot + Vue3 前后端分离 实战wiki知识库系统