2017-08-02 84 views
1

我试图从运行Node.js的卡桑德拉的复杂SQL和使用Cassandra的快递包裹它以下是查询卡珊德拉的复杂的SQL:如何运行通过节点JS

client.execute("select distinct c.objekt PSP, b.bestellung purchase_order, b.details, b.bestellnettowert Budget, c.Interim_Amounts, c.belegdatum, b.cost_centre 
           from 
              (select objekt, sum("Wert/KWahr") Interim_Amounts, belegdatum, bestellung from bdr.cj74 where year(belegdatum) = '2016' group by objekt, belegdatum, bestellung) c, 
              (select bestellung, "Lieferant/Lieferwerk" details, bestellnettowert, belegdatum, "PSP-Elm", "Kostenst." cost_centre from bdr.opexcapex where year(opexcapex.belegdatum) = '2016') b 
           where b."PSP-Elm" = c.objekt 
              and year(c.belegdatum) = year(b.belegdatum) 
              and c.bestellung = b.bestellung", [], 

function(err, result) { 

如果我运行简单的选择声明它正在工作,任何帮助将是伟大的!

回答

0

简而言之,你不能。 Cassandra支持CQL,而不是SQL。 CQL与SQL有相似的语法,但许多SQL关键字在CQL中表现不同。

例如,你不能做JOIN或子查询之类的事情。它确实允许您执行DISTINCT和SUM等某些聚合,但在何时以及如何使用这些方法方面存在限制(只允许在某些键上使用)。以下是查询聚合查询文档的链接:https://docs.datastax.com/en/cql/latest/cql/cql_using/useQueryStdAggregate.html

此外,聚合是Cassandra 3.0的新增功能。如果您使用的是2.x版本,则唯一的选择是在客户端执行一些处理。