gpt4 book ai didi

mysql - SQL Order By Clause 不适用于最大别名

转载 作者:行者123 更新时间:2023-12-04 07:21:24 25 4
gpt4 key购买 nike

我有一个查询

Select tableA.*,  max(`queue_position`) AS `product_advertisements.queue_position` 
from tableA join tableB
group by tableA.attribute
order by `product_advertisements.queue_position` ASC
当查询运行时,它实际上并没有按队列位置排序,
这是我的返回 https://gyazo.com/471749b349d64e94707b9452d4b25417 ,
这是预期的输出, https://gyazo.com/e8c92b2898a404781c9de095f1146143
它与连接属性的排序有关吗?为什么我的 order by 子句被完全忽略

最佳答案

我不知道所有列的名称,但我猜有一个同名的列“product_advertisements.queue_position”,您不想按它排序。相反,您想按 MAX(queue_position)
尝试以下 2 个选项:

  • 使用 MAX 列作为第一列,并使用“ORDER BY 1”,它将 order 子句应用于第一列。
    选择 max(queue_position) AS product_advertisements.queue_position, tableA.*
    从表A连接表B
    按 tableA.attribute 分组
    按 1 ASC 订购;
  • 在 ORDER CLAUSE 中使用“max(queue_position)”
    选择 tableA.*, max(queue_position) AS product_advertisements.queue_position
    从表A连接表B
    按 tableA.attribute 分组
    按 max(queue_position) ASC 排序

  • 无论如何,为什么选择所有列(tableA.*),但只按一个分组? MySQL 接受它,但在其他数据库中是不允许的。

    关于mysql - SQL Order By Clause 不适用于最大别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68478362/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com