此查询返回两个表中的DBKEY
和DBPArentProductKEy
结果。
select
pog.DBKey
,pos.DBParentProductKey
, pro.Name
from ix_spc_planogram as pog with (nolock)
, ix_spc_position as pos with (nolock)
, ix_spc_product as pro with (nolock)
where
pog.dbkey = pos.dbparentplanogramkey
and pos.dbparentproductkey=pro.dbkey
and pog.Value4= 358
示例:
DBKEY DBPArentProduct KEy
1 0123
1 0124
1 0125
2 0126
3 0123
3 0124
3 0125
我现在需要一个查询,以便我确定是否存在具有完全相同产品的重复DBKEYS
。例如DBKEY
1与DBKEY3具有完全相同的DBPArentProductKeys
。我需要找到这个,以便可以识别重复项。考虑这个问题的另一种方法是我想知道有多少订单具有完全相同的产品,订单为DBKEY
,产品为DBPAREntPRoductKey
。
如果可以做任何帮助,将不胜感激。
答案 0 :(得分:0)
SQL有什么味道? Oracle,SQL Server和MySQL可以这样做......
SELECT count(*), DBParentProductKEy
FROM (
select pog.DBKey
,pos.DBParentProductKey
, pro.Name
from ix_spc_planogram as pog with (nolock)
, ix_spc_position as pos with (nolock)
, ix_spc_product as pro with (nolock)
where pog.dbkey = pos.dbparentplanogramkey
and pos.dbparentproductkey=pro.dbkey
and pog.Value4= 358)
GROUP BY DBParentProductKEy
HAVING COUNT(*) > 1