简体   繁体   English

SQL查询仅返回特定列中具有最高值的行

[英]SQL query to only return the rows that have the highest value in a certain column

I have a database I'm working on and I'm trying to figure out how to return every row that has the highest number in a specific column. 我有一个正在使用的数据库,并且试图找出如何返回特定列中编号最高的每一行。

                        SELECT * MAX(version_group_id) = max_version_group_id
                        FROM table
                        GROUP BY max_version_group_id
                        ORDER BY max_version_group_id DESC;`;

I keep getting syntax errors and can't find out what is wrong here. 我不断收到语法错误,在这里找不到错误。 I'm fairly new to sql. 我是sql的新手。

The question is not clear. 问题尚不清楚。 If you want to select the rows whos column value is equal to the the highest column value of the table, use the following query: 如果要选择谁的列值等于表的最高列值的行,请使用以下查询:

SELECT *
FROM table
WHERE version_group_id = (
  SELECT MAX(version_group_id)
  FROM table
)

It has a subquery that finds out which value is the highest. 它有一个子查询,可以找出哪个值最高。


The correct select syntax you try to implement is: 您尝试实现的正确选择语法是:

SELECT *, MAX(version_group_id) AS max_version_group_id

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

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