oracle中有多个LEFT JOIN

时间:2013-02-14 06:44:35

标签: oracle10g

嗨,我正在构建查询。添加第二个左连接后会产生问题: - 在添加第二个连接之前它工作正常。你可以解决这个问题吗

SELECT   u.dept_name AS deptname, u.user_name AS username,
 u.user_id AS userid, u.single_id AS singleid,
 u.email_address AS emailaddress, to_char(m.cur_week_hits) AS empno,
 to_char(m.prev_week_hits) AS mobiletelno,r.role_id , r.role_name 
 to_char(m.cur_week_hits - m.prev_week_hits) AS comptelno
FROM tn_cf_user u
     LEFT JOIN
     (
     SELECT
          SUM (cur_week_hits) AS cur_week_hits,
           SUM (prev_week_hits) AS prev_week_hits,
           user_id
      FROM  pp
         GROUP BY user_id   ) m
     ON u.user_id = m.user_id

      LEFT JOIN
        (
        SELECT ur.role_id , rn.role_name , ur.user_id
            FROM tn_cf_user_role ur , tn_cf_role rn
            WHERE   ur.role_id = rn.role_id
        ) r,
     ON u.user_id = r.user_id 

   AND u.single_id IS NOT NULL
   AND u.user_type IS NULL

由于

1 个答案:

答案 0 :(得分:-1)

试试这个: 在第二个连接中,更改为m.user_id = r.user_id