SELECT * (SQL) 的 Agg 函数的预期行为是什么
What is the expected behavior of Agg functions with SELECT * (SQL)
当 运行 -
时你希望得到什么
select *, max(col1) from table1;
你希望得到什么
- 仅具有 max(col1) 的行
- 旁边有最大 (col1) 值的所有行
不同数据库之间有区别吗?
如果你想要最大值为col1
的一行,那么使用order by
和limit
:
select t1.*
from table1 t1
order by col1 desc
limit 1;
在 MySQL 中,您的查询将 return 一行,其中 *
表示的所有列的值不确定,最大值为 col1
。在其他数据库中,它会 return 一个错误。
当 运行 -
时你希望得到什么select *, max(col1) from table1;
你希望得到什么
- 仅具有 max(col1) 的行
- 旁边有最大 (col1) 值的所有行
不同数据库之间有区别吗?
如果你想要最大值为col1
的一行,那么使用order by
和limit
:
select t1.*
from table1 t1
order by col1 desc
limit 1;
在 MySQL 中,您的查询将 return 一行,其中 *
表示的所有列的值不确定,最大值为 col1
。在其他数据库中,它会 return 一个错误。