在网格视图中显示水平和垂直标题与计数 [英] Display headers horizontal and vertical in gridview with count

查看:78
本文介绍了在网格视图中显示水平和垂直标题与计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,它与SQL表链接,我想水平和垂直显示标题,但我卡住了,不知道怎么做。

我想要的结果显示如下,



- 步骤名称---产品1

| - 步骤1 --------- - 2

| --Step2 ----------- 2

| --Step3 ----------- 2

| --Step4 ----------- 2

| --Step5 ----------- 2



上表中的数字是每一步的数量,

i am使用以下SQL代码,



I have a gridview and it is linked with SQL table, i want to display headers horizontally as well as vertically but i am stuck and have no idea how to do it.
I want the result to be displayed as follows,

--StepName---Product1
|--Step1-----------2
|--Step2-----------2
|--Step3-----------2
|--Step4-----------2
|--Step5-----------2

The numbers in above table are count of each step,
i am using the following SQL code,

select 
  sum(case when currentstepname = 'Step1' then 1 else 0 end) Step1,
  sum(case when currentstepname = 'Step2' then 1 else 0 end) Step2,
  sum(case when currentstepname = 'Step3 then 1 else 0 end) Step3,
  sum(case when currentstepname = 'Step4' then 1 else 0 end) Step4,
  sum(case when currentstepname = 'Step5' then 1 else 0 end) Step5

from Table1





我现在得到的结果如下,



- 步骤1 ---步骤2 ---步骤3 ---步骤4 --- Step5

| - 2 --------- 2 -------- 2 -------- 2 ------ -2 ---- |



我的尝试:



搜索网页但没有得到所需的结果。



And i am getting the result currently as follows,

--Step1---Step2---Step3---Step4---Step5
|--2---------2--------2--------2-------2----|

What I have tried:

Searched the web but not getting the required results.

推荐答案

如果我理解你,你必须使用 Pivot [ ^ ]。

If i understand you well, you have to use Pivot[^].
SELECT StepName, [Product1], [Product2], [Product3]
FROM (
    SELECT StepName, ProductName, COUNT(*) AS StepsCount
    FROM Table1
    GROUP BY StepName, ProductName
) AS DT
PIVOT (SUM(StepsCount) FOR (ProductName) IN ([Product1], [Product2], [Product3])) AS PT





试试!



Try!


这篇关于在网格视图中显示水平和垂直标题与计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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