任何人都可以帮助我以所需的格式获得此输出吗? [英] Can anyone help me to get this output in a required format please ?

查看:58
本文介绍了任何人都可以帮助我以所需的格式获得此输出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的sql表数据,

----------------------

Here is my sql table data,
----------------------

ID	Team	Emp	Status
1	PP	H001	Active
2	AR	H002	In-Active
3	BL	H003	Active
4	EN	H004	Active
5	PP	H005	Active
6	AR	H006	Active
7	BL	H007	In-Active
8	EN	H008	In-Active
9	PP	H009	In-Active
10	AR	H010	In-Active
11	BL	H011	Active
12	EN	H012	In-Active
13	PP	H013	Active
14	AR	H014	Active
15	BL	H015	In-Active
16	EN	H016	In-Active



--------------------------



现在我需要输出就好了,

----------------------- ----


--------------------------

And now i need output is like,
---------------------------

Status	   PP	AR	BL	EN
Active	   3	2	2	1
In-Active	1	2	2	3



---------------------------





请帮帮我。



提前致谢。



我尝试过的事情:



Itried this,

------- ------------ -


---------------------------


Please help me out of this.

Thanks in advance.

What I have tried:

Itried this,
---------------------

SELECT  Status, count(*) FROM [Tbl_Code] group by Status



---------


---------

推荐答案

像这样使用pivot:
Use pivot like this:
SELECT status, [PP],[AR],[BL], [EN] FROM
(SELECT status, team FROM tablename) as src
PIVOT
(
   COUNT(team) FOR team IN ([PP],[AR],[BL], [EN])
) AS output

学习使用PIVOT和UNPIVOT [ ^ ]


这篇关于任何人都可以帮助我以所需的格式获得此输出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆