1

我正在尝试在两个 liferay 表上执行右外连接 -users_并且expandovalue- 以获得结果集。

当我对所有用户进行以下查询时,我得到了想要的结果。

SELECT USER_.FIRSTNAME
     , USER_.LASTNAME
     , USER_.EMAILADDRESS
     , USER_.JOBTITLE
     , expandovalue.data_  
from expandovalue 
     right outer join 
     user_ on expandovalue.classpk = user_.userid 
     and expandovalue.columnid =35695;

当尝试对一组用户(用户组的一部分)执行相同操作时,它会出错。如下查询:

SELECT USER_.FIRSTNAME
     , USER_.LASTNAME
     , USER_.EMAILADDRESS
     , USER_.JOBTITLE
     , expandovalue.data_ 
from expandovalue 
     right outer join
       user_ on expandovalue.classpk 
     in (select userid 
          from user_ 
         where userid 
                in ( select userid 
                      from users_usergroups
                     where usergroupid = 40073
                   ) and status =0) =   user_.userid in
                                             (select userid 
                                                from user_ 
                                               where userid 
                                                  in ( select userid 
                                                       from users_usergroups 
                                                     where usergroupid = 40073
                                                     )
                                              and status =0
                                            ) and expandovalue.columnid =35695

这是给出userid特定用户组中人员 s 的子查询。

(select userid 
   from user_ 
  where userid in 
                 ( select userid 
                     from users_usergroups
                    where usergroupid = 40073) 
                      and status =0
                 ) 

我会朝着一个完全错误的方向前进吗?请指教。

4

1 回答 1

1

试试这个查询:

SELECT USER_.FIRSTNAME,
       USER_.LASTNAME,
       USER_.EMAILADDRESS,
       USER_.JOBTITLE,
       expandovalue.data_
  from expandovalue
  right outer join user_
    on expandovalue.classpk IN
          (select userid
             from user_
             where userid in (select userid
                                from users_usergroups
                                where usergroupid = 40073) and 
                   status = 0) AND
       user_.userid in (select userid
                          from user_
                          where userid in (select userid
                                             from users_usergroups
                                             where usergroupid = 40073) AND
                                status =0) AND
       expandovalue.columnid = 35695

第一个子查询结束后缺少一个“AND”。

于 2012-09-12T19:17:09.567 回答