create or replace view user_view as select distinct(pandaid),user_name from ( select distinct(a.pandaid),a.user_name from (select p.pandaid pandaid,p.name user_name from pj_user p where (p.pandaid,p.ludt) in (select u.pandaid,max(u.ludt) from pj_user u group by u.pandaid)) a union all select distinct(b.pandaid),b.user_name from userinfo b where b.status = '1' ) 我大致说一下 就是pj_user下是按时间为最新更新时间取值 而userinfo是按有效字段status是否为1还是无效的0
select a.id,a.name
from a left outer join b on (a.id=b.id)
/
select distinct(pandaid),user_name
from ( select distinct(a.pandaid),a.user_name
from (select p.pandaid pandaid,p.name user_name
from pj_user p where (p.pandaid,p.ludt) in (select u.pandaid,max(u.ludt) from pj_user u group by u.pandaid)) a
union all
select distinct(b.pandaid),b.user_name
from userinfo b where b.status = '1'
)
我大致说一下 就是pj_user下是按时间为最新更新时间取值 而userinfo是按有效字段status是否为1还是无效的0