我的要求是这样的:
对于在查询中传递的 PROJECTNAME,我必须从表 PSPROJECTITEM 中找出重复项。目的是找出在创建备份或迁移期间出现的重复项目。必须在两个项目之间检查行的重复性,如果它们具有相似的对象,如 objecttype、objectid1 等,并且这些对象的计数匹配,则它们是重复的。
我的问题是我写的查询会提取额外的重复项。
SELECT a.PROJECTNAME
, a.OBJECTTYPE
, a.OBJECTID1
, a.OBJECTVALUE1
, a.OBJECTID2
, a.OBJECTVALUE2
, a.OBJECTID3
, a.OBJECTVALUE3
, a.OBJECTID4
, a.OBJECTVALUE4,
COUNT(*) as duplicate
FROM PSPROJECTITEM a
WHERE a.projectname <> 'AZ_11' and
exists (
SELECT *
FROM PSPROJECTITEM c
WHERE c.projectname = 'AZ_11'
and a.objecttype = c.objecttype
AND a.objectid1 =c.objectid1
AND a.objectvalue1 = c.objectvalue1
AND a.objectid2 = c.objectid2
AND a.objectvalue2 = c.objectvalue2
AND a.objectid3 = c.objectid3
AND a.objectvalue3 = c.objectvalue3
AND a.objectid4 = c.objectid4
AND a.objectvalue4 = c.objectvalue4)
group by a.PROJECTNAME
, a.OBJECTTYPE
, a.OBJECTID1
, a.OBJECTVALUE1
, a.OBJECTID2
, a.OBJECTVALUE2
, a.OBJECTID3
, a.OBJECTVALUE3
, a.OBJECTID4
, a.OBJECTVALUE4
ORDER BY a.projectname
匹配必须在对象的基础上进行,重复是具有相同对象的对象,并且对象的数量也匹配。
记录 PSPROJECTITEM 中项目名称的副本是
A_RP 7 10 AZ_EP_DASHBOARD 39 GBL 0 0
A_RP 46 10 AZ_EP_DASHBOARD 39 GBL 12 PostBuild 0
A_RP 46 10 AZ_EP_DASHBOARD 39 GBL 12 PreBuild 0
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ACCEPTED FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ACCPTRQST_LINK FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ADD_PEER FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ALL_REQUESTS FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_COMPLETED FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DASH_RTNXFR_OK FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DECLINED FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW2 FieldChange
A_RP 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DEL_NO FieldChange
该查询还获取这些值:
AZ_ASH_DASHBOARD 7 10 AZ_EP_DASHBOARD 39 GBL 0 0
AZ_ASH_DASHBOARD 46 10 AZ_EP_DASHBOARD 39 GBL 12 PostBuild 0
AZ_ASH_DASHBOARD 46 10 AZ_EP_DASHBOARD 39 GBL 12 PreBuild 0
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ACCEPTED FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ADD_PEER FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_COMPLETED FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DECLINED FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW2 FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DEL_NO FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DEL_YES FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLDOWN_BTN FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLTOP_BTN FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLUP_BTN FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EERVW_ACTION FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_ACCEPT FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_DECLINE FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_FDBCK_LINK FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_OLD_RVW_LINKFieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GOALS_ACTION FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_MANAGE_FDBCK FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_MGRRVW_ACTION FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_NOMINATED FieldChange
AZ_ASH_DASHBOARD 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_NOTIFY_PB FieldChange
意思是,这些是附加值,除此之外,附加值是这样的。
请帮助我完善此查询,以便获取查询中传递的项目的副本。
使用的数据库是oracle。
这是结果
select * from PSPROJECTITEM where PROJECTNAME = 'AZ_11';
栏目名称:
PROJECTNAME OBJECTID1 OBJECTVALUE1 OBJECTID2 OBJECTVALUE2 OBJECTID3 OBJECTVALUE3 OBJECTID4 OBJECTVALUE4
AZ_11 7 10 AZ_EP_DASHBOARD 39 GBL 0 0
AZ_11 46 10 AZ_EP_DASHBOARD 39 GBL 12 PostBuild 0
AZ_11 46 10 AZ_EP_DASHBOARD 39 GBL 12 PreBuild 0
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ACCEPTED FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ACCPTRQST_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ADD_PEER FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_ALL_REQUESTS FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_COMPLETED FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DASH_RTNXFR_OK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DECLINED FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DELETE_ROW2 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DEL_NO FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DEL_YES FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLDOWN_BTN FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLTOP_BTN FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_DRILLUP_BTN FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EERVW_ACTION FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_ACCEPT FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_DASH_CANCEL FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_DECLINE FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_FDBCK_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_EP_OLD_RVW_LINKFieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GIVEACCPT_FDBCKFieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GIVE_FDBCK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GL_CREATE_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GL_CREATE_MGR FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GL_LIST_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GL_LIST_MGR FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_GOALS_ACTION FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_MANAGE_FDBCK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_MGRRVW_ACTION FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_NOMINATED FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_NOTIFY_PB FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_PCS_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_PENDING FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_REQUEST_FDBCK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_REQUEST_FDBCKS FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_REVIEW_ACTION FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_RQST_FDBCK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_TOTAL_REQUESTS FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_TRANSFER_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_EP_DASH_WRK 2 AZ_UNSOLICITED FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_ARCHIVE_FLG FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_CANCEL FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_FBFILTER FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_FB_COMPL_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_FB_RQST_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_REWORK_PB FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 AZ_SUBMIT_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 RETURN_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 SELECT_ALL FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_FDBCK_WRK 2 TOGGLE1 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_CANCEL FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_COPY FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_COPY_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_EDIT_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GL_CREATE_LINK FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GOAL_FILTER FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GOAL_FILTER1 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GOAL_FILTER2 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GOAL_FILTER3 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_GOAL_FILTER4 FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 AZ_GOALS_WRK 2 AZ_SELECT_ALL FieldChange
AZ_11 48 10 AZ_EP_DASHBOARD 39 GBL 1 DERIVED_PSS 2 SEARCH_BTN FieldChange
提前感谢您的帮助,如果我错过了任何信息,请告诉我。
这是用于测试重复性的查询:
(SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_11'
minus
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='A_RP')
union all
(
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='A_RP'
minus
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_11'
);
为此,它返回空白行。
当我使用这些值运行时:
(SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_11'
minus
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_ASH_DASHBOARD ')
union all
(
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_ASH_DASHBOARD '
minus
SELECT COUNT(*) FROM PSPROJECTITEM
WHERE PROJECTNAME='AZ_11'
);
这返回:
65
0
这意味着,这些不是重复的项目,因为对象不匹配。
只是帮助我解决这个问题,这非常复杂,我没有想法。