1

背景:有多个 DBPArentProductKEy 与 POG.ID 关联。

我需要计算发生的 Pog.DBKEY 的数量。现在结果在总数据库中为 value4 计算总 POG.ID,但我想要与 DBparentproductkey 关联的计数。

select distinct 
    Count(pog.DBKey) as Total,
    pos.DBParentProductKey 
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 pog.Value4 = 358 
group by 
    pog.DBKey, pos.DBParentProductKey
4

1 回答 1

1

拿出pog.DBKeyGROUP BY

另外,我认为您缺少连接条件。您没有针对 table 的连接条件pro

最后,DISTINCT应该不需要。

于 2012-06-19T15:15:00.393 回答