use*_*820 1 sql-server coldfusion
我有一个提供数据的查询
ID Value AttributeID IDParent
286 Fleet 9 284
286 239 10 284
286 1 12 284
208 Rivers 9 -1
208 319 10 -1
208 0 12 -1
Run Code Online (Sandbox Code Playgroud)
这个结果需要改进.有没有办法使用"查询查询"它可以转换为
ID Value PageID Show IDParent
286 Fleet 239 1 284
208 Rivers 319 0 -1
Run Code Online (Sandbox Code Playgroud)
或者什么是更好的方法来做到这一点.
你可以这样做:
select t.ID,
t.Value,
aux1.Value as 'PageID'
aux2.Value as 'Show'
t.IDParent
from tablename t
inner join tablename aux1 on aux1.IDParent = t.IDParent and aux1.AttributeID = 10
inner join tablename aux2 on aux2.IDParent = t.IDParent and aux2.AttributeID = 12
where t.AttributeID = 9
Run Code Online (Sandbox Code Playgroud)