日期:2014-05-16  浏览次数:20848 次

oracle 连接查询
select count(*) as count,o.organ_name from PUB_USERS u,t_req_vote_result r,PUB_Organ o where u.user_id= r.user_id and (select substr(organ_id,2,16) from PUB_Organ) =(select substr(EMPLOYEE_ID,2,16) from PUB_USERS) group by organ_name

在PUB_USERS PUB_Organ两个表有关系 pub_users 里面的 EMPLOYEE_ID 和PUB_Organ表中的organ_id 连接
但是表中的数据时这样的 比如说 EMPLOYEE_ID=S00000000000106 而在PUB_Organ表中organ_id=O00000000000106
请问 怎么写sql 上面那么些报错

------解决方案--------------------
这样不行吗?
SQL code

SELECT COUNT(*) AS COUNT, O.ORGAN_NAME
  FROM PUB_USERS U, T_REQ_VOTE_RESULT R, PUB_ORGAN O
 WHERE U.USER_ID = R.USER_ID
   AND SUBSTR(O.ORGAN_ID, 2, 16) = SUBSTR(U.EMPLOYEE_ID, 2, 16)
 GROUP BY ORGAN_NAME

------解决方案--------------------
探讨
这样不行吗?

SQL code


SELECT COUNT(*) AS COUNT, O.ORGAN_NAME
FROM PUB_USERS U, T_REQ_VOTE_RESULT R, PUB_ORGAN O
WHERE U.USER_ID = R.USER_ID
AND SUBSTR(O.ORGAN_ID, 2, 16) = SUBSTR(U.EMPLOYEE……