我的数据结构如下表所示:
| Name | Foo_A | Foo_B | Foo_C | Bar_A | Bar_B | Bar_C |
--------------------------------------------------------
| abcd | 16 | 32 | 14 | 52 | 41 | 17 |
| ... | ... | ... | ... | ... | ... | ... |
我希望以如下方式查询配置单元中的数据:
| Name | Class | FooVal | BarVal |
----------------------------------
| abcd | A | 16 | 52 |
| abcd | B | 32 | 41 |
| abcd | C | 14 | 17 |
| ... | ... | ... | ... |
我已经意识到并正在使用一个union all,但是使用“横向视图分解”Map数据类型有什么更有效的方法呢?
3条答案
按热度按时间xwbd5t1u1#
交叉连接
class
stack
(参见代码示例)将主表行x3相乘,每行一行class
,然后使用case
派生列所依赖的语句class
价值观。带有小数据集(3行)的交叉连接应转换为Map连接,并在Map程序上执行得非常快。它将只扫描一次表,并且比union all方法的性能要好得多。
7vux5j2d2#
配置单元取消拆分多个列:
3lxsmp7m3#
谢谢回复!请在下面找到另一种比交叉连接更快的方法。