首页 > 代码库 > 一条sql,有分页,表合并查询,多表连接,用于oracle数据库
一条sql,有分页,表合并查询,多表连接,用于oracle数据库
SELECT * FROM (
SELECT TT.*,ROWNUM RN FROM
( SELECT
A.CASE_ID AS TREATID,
A.TYPE AS TYPE,
B.CONTENT AS CONTENT,
B.ADD_USER_ID AS ADDUSERID,
B.Add_User_Type AS ADDUSERTRPE,
A.CREATE_TIME AS CREATETIME,
B.CHECK_TIME as CHECKTIME,
E.ADDUSERTYPE
FROM T_MEDICAL_CASE A
LEFT JOIN T_TREATMENT B ON A.CASE_ID = B.TREAT_ID
LEFT JOIN (select C.PATIENT_ID AS ID, C.USER_NAME, ‘2‘ AS ADDUSERTYPE
from T_PATIENT_INFO C
UNION
select D.DOCTOR_ID AS ID, D.USER_NAME, ‘1‘ AS ADDUSERTYPE
from T_DOCTOR_INFO D) E ON B.ADD_USER_ID = E.ID
WHERE A.PATIENT_ID = v_userid ORDER BY A.CREATE_TIME DESC) TT WHERE ROWNUM <=v_maxPage ) WHERE RN >=v_minPage;
一条sql,有分页,表合并查询,多表连接,用于oracle数据库