如何将水平行转换为垂直SQL Server

时间:2015-05-13 18:38:09

标签: sql sql-server vb.net

查询:

Select 
    COUNT(aciklama)as Permitted,   
    (Select COUNT(aciklama) 
     from Uyari 
     where Aciklama like '%Blocked%') as Blocked 
From 
    Uyari 
where 
    Aciklama like '%Permitted%'

输出:

Permitted     Blocked
----------------------
    74         9194

我想要这样的结果:

Permitted   ...      74
Blocked    ...     9194  

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

这是使用union all

的一个选项
select 'Permitted' action, COUNT(aciklama) as result
from Uyari 
where Aciklama like '%Permitted%'
union all
select 'Blocked' action, COUNT(aciklama)   
from Uyari 
where Aciklama like '%Blocked%'