以下查询返回错误的行数:
SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue,
address.zip AS zip,
customer_map AS customerMap
FROM CUSTOMERS
WHERE customer_group = 'xyz'
GROUP BY keyValue, customerMap, zip
其中列数据类型如下:
keyName String
address EMBEDDEDMAP
customer_map EMBEDDEDMAP
但是,如果更改GROUP BY以使用列名而不是别名,则查询将返回正确的行数:
SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue,
address.zip AS zip,
customer_map AS customerMap
FROM CUSTOMERS
WHERE customer_group = 'xyz'
GROUP BY keyValue, customer_map, address.zip
有趣的是,使用keyName.left(...)
的别名不会影响GROUP BY,但会影响例如:
ifnull(keyName, 'ABC) AS keyValue
使查询返回错误的行数。
请注意,第一个查询不会给出任何错误/警告,只返回错误的行数。
GROUP BY的预期行为是什么?
不幸的是,OrientDB文档没有太多关于GROUP BY的细节。
答案 0 :(得分:0)
查询执行流程如下:
您可以使用
select keyValue,zip,customerMap from (SELECT keyName.left(keyName.indexOf('_Configuration/')) AS keyValue,
address.zip AS zip,
customer_map AS customerMap
FROM CUSTOMERS
WHERE customer_group = 'xyz' )
GROUP BY keyValue, customerMap, zip