SQL MAX of multiple columns?

后端 未结 22 2273
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 02:03

How do you return 1 value per row of the max of several columns:

TableName

[Number, Date1, Date2, Date3, Cost]

I n

22条回答
  •  我寻月下人不归
    2020-11-22 02:11

    Problem: choose the minimum rate value given to an entity Requirements: Agency rates can be null

    [MinRateValue] = 
    CASE 
       WHEN ISNULL(FitchRating.RatingValue, 100) < = ISNULL(MoodyRating.RatingValue, 99) 
       AND  ISNULL(FitchRating.RatingValue, 100) < = ISNULL(StandardPoorsRating.RatingValue, 99) 
       THEN FitchgAgency.RatingAgencyName
    
       WHEN ISNULL(MoodyRating.RatingValue, 100) < = ISNULL(StandardPoorsRating.RatingValue , 99)
       THEN MoodyAgency.RatingAgencyName
    
       ELSE ISNULL(StandardPoorsRating.RatingValue, 'N/A') 
    END 
    

    Inspired by this answer from Nat

提交回复
热议问题