我试图找到在给定数据库的多个表中出现的列。我已经成功地生成了一个结果集,它给出了列名、表名和额外的秩列,并为多个引用提供了一个标志(0或1)。
我只是想知道是否有可能根据上一栏过滤这个cte
;with CTE as
(
SELECT c.name AS ColName, t.name AS TableName, ROW_NUMBER() over (partition by c.name order by c.name) as NumberofOcuurance
FROM sys.columns c
JOIN sys.tables t
ON c.object_id = t.object_id
)
select *,
case
when LEAD(NumberofOcuurance,1) over (order by colName) = NumberofOcuurance then 0
when LEAD(NumberofOcuurance,1) over (order by colName) <> NumberofOcuurance then 1
End as Morethan1
from CTE
2条答案
按热度按时间nlejzf6q1#
只需使用子查询/派生表,例如。
rfbsl7qr2#
为什么不直接使用
information_schema
意见?