select max(maxvalue),id from
(
select max(date) maxvalue,id from table1
union all
select max(date) maxvalue,id from table2) as aano tested !
(
select max(date) maxvalue,id from table1
union all
select max(date) maxvalue,id from table2) as aano tested !
2、select case when max(adate)>max(bdate) then max(aid) else max(bid) end from (select a.date adate,a.id aid,b.date bdate,b.id bid from test1 a,test3 b where a.id=b.id)
你是用两句来实现的,我想用一句,因为查出的条件还要嵌套到其他语句中
这是我的方案,其中ALL去掉也可以,不过效率会底点,旁边没环境,没测过。
pandc2002(pc)的思路不错哦,但是需要添加 group by id
zhaoyongzhu(zhaoyongzhu)写法中的 case when 在其他情况下会很有用的