在SQL中列为列 [英] Row as Column in SQL

查看:65
本文介绍了在SQL中列为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在SQL中有两个表
1.有问题的SchoolQuestion
ID(p.k)
IssueStatusId(F.K)
问题varchar(max)
2.具有字段的IssueStatusMaster
ID(p.k)
StatusName varchar(max)

现在IssueStatusMaster看起来像这样:
ID StatusName
-------------------------------------------------- ---------------------------------
1个已解决
2个待审核
保留3个
... ...

和SchoolQuestion看起来像这样.
ID IssueStatusId问题
-------------------------------------------------- ----------------------------------
1 1期内容
2 1期于lms
表中的3 2期
4 3期,坐在椅子上
现在我想要的是一个查询,它给出这样的结果...

已解决的暂挂状态
2 1 3

此查询表示从行到列的状态名称,并从schoolquestion表中对其进行计数

请帮我解决这个问题...

预先感谢,
问候,

Krunal Panchal

Hello everyone,

I have two tables in SQL
1. SchoolQuestion having fields
Id (p.k)
IssueStatusId (F.K)
Question varchar(max)
2. IssueStatusMaster having fields
Id (p.k)
StatusName varchar(max)

now the IssueStatusMaster looks like this:
Id StatusName
-----------------------------------------------------------------------------------
1 resolved
2 pending
3 onhold
... ...

and SchoolQuestion looks like this..
Id IssueStatusId Question
------------------------------------------------------------------------------------
1 1 issue in content
2 1 issue in lms
3 2 issue in table
4 3 issue in chair

Now what i want is one query which gives the result like this...

Resolved Pending Onhold
2 1 3

what this query indicates the statusname from rows to columns and gives it count from schoolquestion table

Please help me out how to do this...

Thanks in advance,
Regards,

Krunal Panchal

推荐答案

看看我的可爱文章:
在SQL Server 2005、2008和2008 R2中使用多维数据集和事件处理程序进行动态透视 [
look at my lovely article:
Dynamic Pivoting with Cubes and eventhandlers in SQL Server 2005, 2008 and 2008 R2[^]


在这里

在SQL Server中透视数据 [
Here you go

Pivoting data in SQL Server[^]


这篇关于在SQL中列为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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