![](/img/trans.png)
[英]How can I sort values in a table based on a column from another table and a column from the original table?
[英]How can I sort table based on calculated column on the fly
SELECT addressId, min(school), min(grocery)
FROM geo_address
GROUP BY addressId
ORDER BY min(grocery), min(school)
我在上面的查詢中添加了min(school) + min(grocery)
作為分數,這里是結果
我想根據分數(動態添加的列)進行排序,但是當我嘗試它時,我在 kibana 控制台上收到錯誤消息。 第一個錯誤是 => 無法按非分組列 [score] 排序。 為了解決這個問題,我嘗試按分數分組。 然后我得到另一個錯誤 => 無法使用聚合 [MIN] 進行分組。 請幫我根據分數排序。
嘗試做一個子查詢
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.