当前位置: 代码迷 >> Oracle开发 >> oracle distinct 字段的有关问题求解
  详细解决方案

oracle distinct 字段的有关问题求解

热度:266   发布时间:2016-04-24 07:19:16.0
oracle distinct 字段的问题求解
Code1:
SQL code
SELECT a.mps_id, b.MONTH  FROM (SELECT   mps_id            FROM smicscmadm.scm_mps_mast           WHERE del_flag = 'N' AND TYPE = 'MPS' AND ROWNUM <= 6        ORDER BY mps_id DESC) a,       (SELECT mps_id, YEAR || MONTH AS MONTH          FROM scm_mps_qty) b WHERE a.mps_id = b.mps_id


Code2:
SQL code
SELECT DISTINCT a.mps_id, b.MONTH           FROM (SELECT   mps_id                     FROM smicscmadm.scm_mps_mast                    WHERE del_flag = 'N' AND TYPE = 'MPS' AND ROWNUM <= 6                 ORDER BY mps_id DESC) a,                (SELECT mps_id, YEAR || MONTH AS MONTH                   FROM scm_mps_qty) b          WHERE a.mps_id = b.mps_id


Code1 在结束后有返回结果,但是Code2在执行结束后没有返回结果,

Code2相对于Code1的唯一区别是加了distinct 关键字. db是Oracle 11g

希望大家帮忙看看是哪里写错了.

------解决方案--------------------
SQL code
SELECT A.MPS_ID, B.MONTH  FROM (SELECT MPS_ID          FROM (SELECT MPS_ID                  FROM SMICSCMADM.SCM_MPS_MAST                 WHERE DEL_FLAG = 'N'                   AND TYPE = 'MPS'                 ORDER BY MPS_ID DESC)         WHERE ROWNUM <= 6) A,       (SELECT MPS_ID, YEAR || MONTH AS MONTH FROM SCM_MPS_QTY) B WHERE A.MPS_ID = B.MPS_ID;
  相关解决方案