1

次のようなデータを配信するクエリがあります

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  

この結果は改良する必要があります。「クエリのクエリ」を使用して次のように変換できる方法はありますか

ID  Value   PageID     Show IDParent
286 Fleet   239         1    284
208 Rivers  319         0   -1          

またはこれを行うためのより良い方法は何ですか。

4

1 に答える 1

5

次のように実行できます。

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
于 2012-05-10T12:53:15.060 に答える