declare @s varchar(8000)
set @s=''
select @s=@s+',['+用户名+']=sum(case 用户名 when '''+用户名+''' then 1 else 0 end)'
from 表1
gorup by 用户名
exec('select 状态'+@s+' from 表2 group by 状态')
set @s=''
select @s=@s+',['+用户名+']=sum(case 用户名 when '''+用户名+''' then 1 else 0 end)'
from 表1
gorup by 用户名
exec('select 状态'+@s+' from 表2 group by 状态')
这一句是什么意思呢,能不能解释一下,十分谢谢,麻烦你了我一定加分, 好吗?