[英]SQL select max values
例如,在myValue列中有值'X','Y','Z',''
并想做类似选择max(myValue)
所以我想要一个值,其中X = 1,Y = 2和Z = 0的值最大
select max(
case myValue
when 'X' then 1
when 'Y' then 2
when 'Z' then 0
end) myValue
from myTable
(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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.