Oracle to re-query

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43378945/article/details/100041208

The distinct of
1.distinct + single field, the field indicates the de re
2.distinct + column1 + column2 is represented by using a plurality of fields combined to heavy

Method a: GROUP BY packet deduplication

SELECT T.DOCTOR_ID AS FDOCTORCODE,
      max(T.DOCTOR_NAME) AS FDOCTORNAME,
      max(T.DOCTOR_PHONE) AS FDOCTORPHONE,
      max(T.ORG_ID) AS FORGID,
      max(T.DEPENT_ID) AS FDEPTCODE
 FROM CONSULT_SCHEDULE T
WHERE ORG_ID = '134557'
  AND DEPENT_ID = '1004'
GROUP BY DOCTOR_ID

Method Two:

SELECT T.DOCTOR_ID    AS FDOCTORCODE,
       T.DOCTOR_NAME  AS FDOCTORNAME,
       T.DOCTOR_PHONE AS FDOCTORPHONE,
       T.ORG_ID       AS FORGID,
       T.DEPENT_ID    AS FDEPTCODE
  FROM CONSULT_SCHEDULE T,
       (SELECT MAX(ROWID) ROWID2
          FROM CONSULT_SCHEDULE
         WHERE ORG_ID = '416211338'
           AND DEPENT_ID = '1004'
         GROUP BY DOCTOR_ID) T2
 WHERE T.ROWID = T2.ROWID2

Guess you like

Origin blog.csdn.net/qq_43378945/article/details/100041208