如何 select max(column) 和同一请求 teradata 中的一列

how to select max(column) and a column in the same request teradata

我需要 select 使用 TeraData SQL Assitant

在同一请求中获取列的最大值和列本身

我试过了:

select distinct id, col1, max(col1) from tab where id='myId' group by col1,id;

我也试过了:

SELECT DISTINCT a.id, a.col1 FROM tab a
INNER JOIN (SELECT max(a.col1) AS maxINT,id FROM tab GROUP BY id)x
ON  a.id = x.id
WHERE a.I_INTNE_DOSS_FIN = 'myId' ;

问题我在 col1 和 max(col1) 中都有 col1 的值

有什么想法吗?

提前致谢。

我认为您需要 ,其中 col1 对每个 id.

具有更大的值

在 Teradata 中,您可以使用 row_number()qualify 执行此操作:

select *
from tab
qualify row_number() over(partition by id order by col1 desc) = 1

我想你只想要一排。如果是:

select top (1) t.*
from tab 
where id = 'myId'
order by col1 desc;

您似乎希望在同一个 Select 中同时包含详细信息和聚合信息。这很容易使用 Windowed Aggregates,可能

select id, col1, max(col1) over ()
from tab 
where id='myId'