【问题标题】:Order 2 columns by the combinations of both of the max values in SQL通过 SQL 中两个最大值的组合对 2 列进行排序
【发布时间】:2020-11-25 15:20:53
【问题描述】:

例如,我有这张表(值是完全随机的):

long | lat | fare_amout | total_people |
----------------------------------------
23,32 64,67    450           4
64,67 78,27    543           2
25,32 98,07    458           1
12,32 44,65    323           7
93,42 24,19    398           9
...

所以基本上 total_people 是相同坐标出现在桌子上的次数(我通过简单的计数得到结果),fare_amout 是具有相同坐标的值的平均值。 我想订购我的桌子,以便在第一行获得 fare_amount 和 total_people 组合更高的坐标。有什么建议吗?

【问题讨论】:

  • 请解释您所说的“fare_amount 和 total_people 的更高组合”是什么意思。
  • 你应该向我们展示想要的结果,而不仅仅是描述它。

标签: mysql sql apache-spark apache-spark-sql sql-order-by


【解决方案1】:

这是你想要的吗?

order by total_people desc, fare_amount desc

它首先通过total_people 订购。如果有关系,则通过fare_amount。

如果“更高的组合”是指支付的总金额,那么您可以改为使用:

order by total_people * fare_amount desc

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 1970-01-01
    • 2017-03-30
    • 2014-02-11
    • 1970-01-01
    • 2019-03-17
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多