错误:使用枢轴将行转换为cassandra中的列

问题描述:

我应该在cassandra中编写一个SQL查询以将几行显示为列。表格看起来像这样的值,其范围从1,2,3,... 42。错误:使用枢轴将行转换为cassandra中的列

+--------+-----------+-------------------+-------+ 
|asset_id|tag_type_id|   datetime| value| 
+--------+-----------+-------------------+-------+ 
|  1|   1|2017-07-28 11:25:...|1202.65| 
|  1|   1|2017-07-28 11:24:...|1212.17| 
|  1|   1|2017-07-28 11:23:...|1214.51| 
|  1|   1|2017-07-28 11:21:...|1210.79| 
|  1|   1|2017-07-28 11:20:...|1207.01| 
|  1|   1|2017-07-28 11:19:...|1208.17| 
|  1|   1|2017-07-28 11:18:...| 1205.7| 
|  1|   1|2017-07-28 11:16:...|1206.11| 
|  1|   1|2017-07-28 11:13:...|1208.53| 
|  1|   1|2017-07-28 11:11:...|1207.82| 
|  1|   1|2017-07-28 11:10:...|1205.05| 
|  1|   1|2017-07-28 11:09:...|1205.56| 
|  1|   1|2017-07-28 11:08:...|1204.55| 
|  1|   1|2017-07-28 11:06:...| 92.17| 
|  1|   1|2017-07-28 11:05:...|1213.93| 
|  1|   1|2017-07-28 11:00:...|1205.13| 
|  1|   1|2017-07-28 10:59:...|1204.42| 
|  1|   1|2017-07-28 10:54:...|1209.42| 
|  1|   1|2017-07-28 10:52:...| 1209.6| 
|  1|   1|2017-07-28 10:50:...|1213.63| 
+--------+----------+--------------------+-------+ 

我需要看值39的tag_type_id和40列,而不是看到在同一个表中的一行。我希望它喜欢这个

asset_id tag_type_id datetime  value tag_type_id datetime  value 
1   39  2017-07-28 11:25 90 40  2017-07-28 11:25 0.3 
1   39  2017-07-28 11:24 91 40  2017-07-28 11:24 0.9 
1   39  2017-07-28 11:23 90 40  2017-07-28 11:23 0.024 
1   39  2017-07-28 11:22 89 40  2017-07-28 11:22 0.9 
1   39  2017-07-28 11:21 91 40  2017-07-28 11:21 0.25 

我尝试使用透视像here它做的事,但它抛出错误:

select * 
from 
(
select tag_type_id, datetime, value 
from energydata.demodata where asset_id = 1 
) src 
pivot 
(
sum(value) 
for tag_type_id in ([39],[40]) 
) piv; 

com.datastax.driver.core.exceptions.SyntaxError: line 3:0 no viable alternative at input '(' (select *from[(]...)
com.datastax.driver.core.exceptions.SyntaxError: line 3:0 no viable alternative at input '(' (select *from[(]...)

我应该怎么做才能查看表像上面?

谢谢。

+0

尝试自己加入相应的日期时间 –

+0

你使用sql-server或cassandra? –

+0

我正在使用cassandra。我在cassandra的SQL控制台中写这些查询 –

select t1.tag_type_id, t1.datetime, t1.value, 
     t2.tag_type_id, t2.datetime, t2.value 
from table t1 
join table t2 on t1.tag_type = 39 and t2.tag_type = 40 and 
       t1.datetime = t2.datetime 
+0

您好,我拥有同一个表中的所有内容。没有不同的表 –

+0

肯定,我使用自联接,一切都在同一张表中,名为“表” –

+0

@RadimBačaCassandra不支持连接...现在,因为sql-server标签被删除,所以这个答案没有帮助 –