简体   繁体   English

如何根据计算列动态对表格进行排序

[英]How can I sort table based on calculated column on the fly

I have table This table is obtained by sql query below我有表这个表是通过下面的sql查询得到的

SELECT addressId, min(school), min(grocery)
FROM geo_address 
GROUP BY addressId 
ORDER BY min(grocery), min(school)

I added min(school) + min(grocery) as score to above query here is the result我在上面的查询中添加了min(school) + min(grocery)作为分数,这里是结果

I want to sort based on score(column added on the fly) but when I try it I get an error on the kibana console.我想根据分数(动态添加的列)进行排序,但是当我尝试它时,我在 kibana 控制台上收到错误消息。 The first error is => can not order by non grouped column[score].第一个错误是 => 无法按非分组列 [score] 排序。 To fix this I tried to group by score.为了解决这个问题,我尝试按分数分组。 Then I got another error => Cannot use an aggregate [MIN] for grouping.然后我得到另一个错误 => 无法使用聚合 [MIN] 进行分组。 Please help me on ordering based on score.请帮我根据分数排序。

try doing a subquery尝试做一个子查询

SELECT * FROM (SELECT addressID, MIN(school) as school, MIN(grocery) as grocery
                FROM geo_address
                GROUP BY 1) t
ORDER BY addressid ASC, grocery ASC, school ASC;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM