0

我使用 IBM DB2 SQL。

这是我当前的查询:

select 
EXSHPE as "Shape",
EXDLVY as "Delivery",

  Sum(Case When EXSURF = 'Print' Then EXRLTO Else 0 End) As Retail_Print,
  Sum(Case When EXSURF = 'Pattern' Then EXRLTO Else 0 End) as Retail_Pattern,
  Sum(Case When EXSURF = 'Solid' Then EXRLTO Else 0 End) As Retail_Solid,
  Sum(Case When EXSURF = 'UnknownA' Then EXRLTO Else 0 End) as Retail_UnknownA,
  Sum(Case When EXSURF = 'UnknownB' Then EXRLTO Else 0 End) As Retail_UnknownB,
  Sum(Case When EXSURF = 'UnknownC' Then EXRLTO Else 0 End) as Retail_UnknownC,

  Sum(Case When EXSURF = 'Print' Then EXWHLO Else 0 End) As Wholesale_Print,
  Sum(Case When EXSURF = 'Pattern' Then EXWHLO Else 0 End) as Wholesale_Pattern,
  Sum(Case When EXSURF = 'Solid' Then EXWHLO Else 0 End) As Wholesale_Solid,
  Sum(Case When EXSURF = 'UnknownA' Then EXWHLO Else 0 End) as Wholesale_UnknownA,
  Sum(Case When EXSURF = 'UnknownB' Then EXWHLO Else 0 End) As Wholesale_UnknownB,
  Sum(Case When EXSURF = 'UnknownC' Then EXWHLO Else 0 End) as Wholesale_UnknownC,

  Sum(Case When EXSURF = 'Print' Then EXUNTO Else 0 End) As Units_Print,
  Sum(Case When EXSURF = 'Pattern' Then EXUNTO Else 0 End) as Units_Pattern,
  Sum(Case When EXSURF = 'Solid' Then EXUNTO Else 0 End) As Units_Solid,
  Sum(Case When EXSURF = 'UnknownA' Then EXUNTO Else 0 End) as Units_UnknownA,
  Sum(Case When EXSURF = 'UnknownB' Then EXUNTO Else 0 End) As Units_UnknownB,
  Sum(Case When EXSURF = 'UnknownC' Then EXUNTO Else 0 End) as Units_UnknownC,

  Sum(Case When EXSURF = 'Print' Then EXAURA Else 0 End) As Actual_AUR_Print,
  Sum(Case When EXSURF = 'Pattern' Then EXAURA Else 0 End) as Actual_AUR_Pattern,
  Sum(Case When EXSURF = 'Solid' Then EXAURA Else 0 End) As Actual_AUR_Solid,
  Sum(Case When EXSURF = 'UnknownA' Then EXAURA Else 0 End) as Actual_AUR_UnknownA,
  Sum(Case When EXSURF = 'UnknownB' Then EXAURA Else 0 End) As Actual_AUR_UnknownB,
  Sum(Case When EXSURF = 'UnknownC' Then EXAURA Else 0 End) as Actual_AUR_UnknownC,

  Sum(Case When EXSURF = 'Print' Then EXMERA Else 0 End) As Merch_AUR_Print,
  Sum(Case When EXSURF = 'Pattern' Then EXMERA Else 0 End) as Merch_AUR_Pattern,
  Sum(Case When EXSURF = 'Solid' Then EXMERA Else 0 End) As Merch_AUR_Solid,
  Sum(Case When EXSURF = 'UnknownA' Then EXMERA Else 0 End) as Merch_AUR_UnknownA,
  Sum(Case When EXSURF = 'UnknownB' Then EXMERA Else 0 End) As Merch_AUR_UnknownB,
  Sum(Case When EXSURF = 'UnknownC' Then EXMERA Else 0 End) as Merch_AUR_UnknownC

from EXOWMSPD
Where (EXCO || '/' || EXDIV)  = ?
Group By
  EXSHPE,
  EXDLVY
Order By
  EXSHPE DESC,
  EXDLVY DESC

数据库如下所示: 在此处输入图像描述

我需要旋转 Surface,但是是动态的。问题是,我只知道前 3 个表面描述。但我需要为最多 6 人做好准备。

有没有办法可以动态地旋转它来抓取前 6 个表面。

例子,

RETAIL_DOLLARS_1   10.00
RETAIL_DOLLARS_2   20.00
RETAIL_DOLLARS_3   50.00
RETAIL_DOLLARS_4   0.00
RETAIL_DOLLARS_5   0.00
RETAIL_DOLLARS_6   0.00

在这个例子中,找到了 3 个表面的数据,另外 3 个我想用 0 填充。

我正在使用它来制作报告,我将隐藏 SURFACE_DESCRIPTION_X 等于“”的列。

有没有办法做到这一点?

谢谢

4

1 回答 1

0

如果您想对各个维度上的数据进行多维数据集,请尝试

 GROUP BY CUBE

条款

于 2012-11-07T14:27:54.013 回答