我有两个表联合在一起
Files
ID | FileName | FileContent | FolderCategoryId |
FolderCategory
ID | FolderCategoryName | FolderParentCategoryId |
以下是我的疑问:
WITH UnionFiles(FileCategoryId, FileCategoryName, FileParentCategoryID, FileParentName, FileCategoryType) AS (
SELECT fc.ID AS FileCategoryId
,fc.FolderCategoryName as FileCategoryName
,fcparent.ID AS FileParentCategoryID
,fcparent.FolderCategoryName AS FileParentName
,FileCategoryType = 0
FROM [dbo].FolderCategory AS fc
LEFT JOIN [dbo].FolderCategory
AS fcparent
ON fc.FolderParentCategoryId = fcparent.ID
UNION
SELECT
f.ID as FileCategoryId
,f.FileName as FileCategoryName
,f.FolderCategoryId as FileParentCategoryId
,ffcparent.FolderCategoryName AS FileParentName
,FileCategoryType = 1
FROM [dbo].Files as f
LEFT JOIN [dbo].FolderCategory as ffcparent
ON f.FolderCategoryId = ffcparent.ID
)
SELECT *
FROM UnionFiles
我想要实现的是隐藏没有子级的FileCategoryName。这可能吗?先谢谢