一条sql,有分页,表合并查询,多表连接,用于oracle数据库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一条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数据库的主要内容,如果未能解决你的问题,请参考以下文章

MySQL千万级多表关联SQL语句调优

SQL多表查询

SQL语句中两个表的连接

MySQL百万级千万级数据多表关联SQL语句调优

SQL总结 连表查询

mysql多表查询合并到一个临时表,怎么再加一列并把各自的表名加上?