SQL选择最大值

时间:2014-04-15 20:59:01

标签: sql

我有例如价值观' X'' Y'' Z'' '在列myValue

并想做一些像select max(myValue)

这样的事情

所以我想要一个值,一个值最高的值,其中X = 1,Y = 2,Z = 0

2 个答案:

答案 0 :(得分:1)

select max(
    case myValue
        when 'X' then 1
        when 'Y' then 2
        when 'Z' then 0
    end) myValue
from myTable

答案 1 :(得分:-1)

(select max(PurDate) as mb,prodid as pd
from batch group by ProdId ) as rs 
on p.RndId = b.ProdId 
and p.ComId = c.RndId
where b.PurDate = rs.mb 
and b.ProdId = rs.pd 
and p.RndId in (select distinct prodid 
                from TranItem as ci, TranMain 
                as tm 
                where tm.RndId = ci.TranId 
                and tm.Invdate between '2016-May-01' and '2016-May-31')