有这样的数据
Id Flag Name
8001 A1 Name1
8001 A2 Name2
Flag字段只有A1,A2两个值,我想查询这样的数据
Id Flag1 Flag2
8001 Name1 Name2
Sql语句应该怎么写???
------解决方案--------------------------------------------------------
交叉表.参考http://community.csdn.net/Expert/topic/5283/5283990.xml?temp=0.0753816734419119
------解决方案--------------------------------------------------------
select Id,(case when Flag= 'A1 ' then 'name1 ') as Flag1,(case when Flag= 'A2 ' then 'name2 ') as Flag2 from Table
------解决方案--------------------------------------------------------
select Id,(case when Flag= 'A1 ' then 'name1 ' end) as Flag1,(case when Flag= 'A2 ' then 'name2 ' end) as Flag2 from Table