问题描述
大家好,
这是我的桌子:
表A:
项目ID描述供应商
1456 IC 74 HC100 X
3459 IC 74 LS221 B
1456 IC 74 LS166 Y
3769 IC 74 LS139 F
6464 IC 74 LS367 G
1456 IC 74 S 74 L
.
.
..继续
在这里,我需要检查ItemID 1456,其中有1个以上的供应商X,Y,L
从表A使用SQL查询.
这样,我需要从具有超过1个供应商的表A中查找所有ItemID?
请帮助..
Hi all,
This is my table:
Table A:
ItemID Description Supplier
1456 IC 74 HC100 X
3459 IC 74 LS221 B
1456 IC 74 LS166 Y
3769 IC 74 LS139 F
6464 IC 74 LS367 G
1456 IC 74 S 74 L
.
.
..going on
Here I need to reteive the ItemID 1456 which has more than 1 suppliers X,Y,L
from the TABLE A using SQL query.
Like this i need to find all the ItemIDs from the TABLE A which has more than 1 suppliers?
Kindly help..
推荐答案
Select ItemID,Count(ItemID) FROM TableA group by ItemID Having Count(ItemID)>1
SELECT
TableA_1.ItemId
FROM
dbo.TableA TableA_1
INNER JOIN dbo.TableA TableA_2 ON
TableA_1.ItemId = TableA_2.ItemId
AND TableA_1.SupplierId <> TableA_2.SupplierID
--This should only give you the duplicated ItemId with different SupplierId, if you only want the duplicated ItemId, remove the last condition.
希望对您有所帮助.
Hope it helps.
这篇关于从SQL中的表检索重复的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!