gpt4 book ai didi

mysql - SQL - 选择具有最大值的所有行

转载 作者:可可西里 更新时间:2023-11-01 06:37:55 28 4
gpt4 key购买 nike

我有这个 SQL 查询:

SELECT id, COUNT(*) AS price
FROM (SELECT * FROM rt WHERE somecondition) AS st
JOIN tt
ON st.id = tt.id
GROUP BY id;

现在,我想选择表格中具有最高价格的所有行。我已经试过了,不幸的是,它根本没有返回任何行:

SELECT id, COUNT(*) AS price
FROM (SELECT * FROM rt WHERE somecondition) AS st
JOIN tt
ON st.id = tt.id
GROUP BY id
HAVING price = MAX(price);

我有点迷路了,有人有什么指点吗?

最佳答案

这对我来说很简单:

select * from <table> 
where <column name> in(
SELECT MAX(column name) FROM table
)

关于mysql - SQL - 选择具有最大值的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11381674/

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