MAX函数...从select语句中使用Max函数作为列名

时间:2014-04-25 21:04:06

标签: sql sql-server max

我不确定我是否可以这样做:

在select语句中,我使用了以下语句:

case when table1.EffectiveDate > table1.IssueDate then  table1.EffectiveDate else table1.IssueDate end as Result

它有效并显示结果列

但是我还要显示MAX(结果)

我该怎么办?

SELECT
case when table1.EffectiveDate > table1.IssueDate then  table1.EffectiveDate else table1.IssueDate end as Result

FROM …

Where  …

Group By….

1 个答案:

答案 0 :(得分:0)

你几乎在你的问题中提到了答案

 SELECT 
 max(
 case when table1.EffectiveDate > table1.IssueDate 
     then table1.EffectiveDate 
 else table1.IssueDate end
 ) as Result

 FROM …

 Where … 

如果你还想要同时获得它们: 从(

)中选择结果,最大值(结果)
SELECT 
case when table1.EffectiveDate > table1.IssueDate 
then table1.EffectiveDate 
else table1.IssueDate end
as Result

FROM …

Where …)

Group by Result
相关问题