本文介绍了如何透视SQL Querry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server中,我有以下情况

实际:-

In SQL server ,I have following scenario

Actual:-

select datename(month,Date)[Month],IsAttend[Attend]  from tblAttend



输出:

月份   参加
一月  是
一月  是
一月   否
一月   否
一月  是
2月  是的
2月  是的
2月  否
2月  是的
3月    是
3月    是
3月     否
3月     否
3月    是
3月     否
3月    是

我所需的场景:

月   是     否
一月                   22月       1
3月          2

请尽快提供解决方案...
thanx in Advanced ...



output:

Month   Attend
January   Yes
January   Yes
January   No
January   No
January   Yes
February   Yes
February   Yes
February   No
February   Yes
March      Yes
March      Yes
March      No
March      No
March      Yes
March      No
March      Yes

My required scenrio:

Month    Yes    No
January    3    2
Febuary   3   1
March     4    2

Please give a solution ASAP...
thanx in advanced...

推荐答案

select [monthname]  as mo,[attend] as att
from (select monthname ,attend  from mon)ps
pivot
(
count(attend)
for monthname in ([January],[February],[March])
)as pvt




您可能会有所帮助




It may be help u


select [monthname],[YES],[No]
from
(select * from mon )source pivot
(count(attend) for attend in ([Yes],[No]))pt

order by monthname


这篇关于如何透视SQL Querry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:53