我有表"值":
int id;
double amount;
Date date;
String cryptoName;
我需要收到" date"和#34;加密名称"并得到类似的东西:
btc ltc drk 42coin
27-DEC-14 0.2 5.0 100.0 0.01
28-DEC-14 0.22 5.5 99.5 0.02
29-DEC-14 0.23 6.1 100.6 0.03
30-DEC-14 0.25 6.0 101.2 0.03
我可以这样做:
select "Values"."date", LISTAGG("amount", ', ') WITHIN GROUP (ORDER BY "cryptoName") as "result" from "Values" GROUP BY "Values"."date"
但在这种情况下,我会收到两列:" date"和"结果"我的名单,但我需要收到" date"列和几列,取决于多少独特" cryptoName"在表中 我怎么能这样做?
答案 0 :(得分:0)
从11g R1起,您可以使用PIVOT操作员。看看例如: http://oracle-base.com/articles/11g/pivot-and-unpivot-operators-11gr1.php
或者您可以使用DECODE函数和SUM,如果您知道列ctyptoName的所有唯一值,如下所示:
select date,
sum(decode(cryptoName,'value1',amount,0)) as Value1
,sum(decode(cryptoName,'value2',amount,0)) as Value2
,...
from Values
group by date