从两张表里select出想要的数据
-----------------------------------
col1 col2 col3 col4
1 1 number number
2 2 number number
3 3 number number
4 1 number number
5 2 number number
................................
-----------------------------------
列1有5种值 列2有三种值 问:能否把列3列4分成多列:
例如:
分成30列 aa1,aa2,ba1,ba2,ca1,ca2.......ec1,ec2
当col1 = 1 且 col2 = 1时,列aa1 的值等于列3 列aa2的值等于列4 其它28个列值为0
当col1 = 2 且 col2 = 1是,列ba1 的值等于列3 列ba2的值等于列4 其它28个列的值为0
。。
每一行都这么处理 sql语句肿么写????求教!!!
-----------------------------------
col1 col2 col3 col4
1 1 number number
2 2 number number
3 3 number number
4 1 number number
5 2 number number
................................
-----------------------------------
列1有5种值 列2有三种值 问:能否把列3列4分成多列:
例如:
分成30列 aa1,aa2,ba1,ba2,ca1,ca2.......ec1,ec2
当col1 = 1 且 col2 = 1时,列aa1 的值等于列3 列aa2的值等于列4 其它28个列值为0
当col1 = 2 且 col2 = 1是,列ba1 的值等于列3 列ba2的值等于列4 其它28个列的值为0
。。
每一行都这么处理 sql语句肿么写????求教!!!
(case when tehn end) as aa2
......
写30个case when 的话 我也能写出来 不过太麻烦了吧 有木有简单的办法?