条件为 table teradata 的 col x 的最小值

min of col x with condition from table teradata

我想找到满足另一个条件的日期列的最小值

即 table :

ID     date  condition   ... 

1      3/15   0
1      4/15   1
5123   5/15   1
5123   7/15   1
5123   1/15   0 
2      2/15   0
2      1/15   1
2      1/15   1

我想要 select 语句中的一行,而不过滤 table 的其余部分,以生成:

ID    date
1     4/15 
5123  5/15
2     1/15

我试过了:

min( date with condition = 1 )

min( date where condition = 1 )

case when   condition=1  then min(date) end  

但出现语法错误。

对于每个Id,如果你想要最小日期,你需要使用GROUP BY

SELECT ID, MIN(Date) AS Date
FROM TableName
WHERE Condition = 1
GROUP BY ID 

"我不想过滤剩下的table",使用case表达式做条件聚合:

select id, min(case when condition = 1 then date end)
from tablename
group by id