如何在sqlite中过滤不一致的记录
假设我有以下记录的SQLite表:
recid | ProduciD | ProductName |
---|---|---|
1 | 1 | 产品A |
2 | 2 | 产品B |
3 | 2 | 产品C |
4 | 3 | 产品D |
5 | 3 | 产品D |
RECID =主键,自动增量。
如果我运行:
SELECT productID, productName
FROM table
GROUP BY productID, productName
结果是:
ProductID | ProductName |
---|---|
1 | 产品A |
2 | 产品B |
2 | 产品C |
3 | 产品D |
如您所见,ProductID 2具有不一致的productName:产品B和产品C
。如何运行查询只是为了检测不一致的查询?例如,我希望结果是:
productid | productname |
---|---|
2 | product b |
2 | 产品c |
Say I have SQLite table with the following records:
recID | productID | productName |
---|---|---|
1 | 1 | Product A |
2 | 2 | Product B |
3 | 2 | Product C |
4 | 3 | Product D |
5 | 3 | Product D |
recID = primary key, auto increment.
If I run:
SELECT productID, productName
FROM table
GROUP BY productID, productName
Result is:
productID | productName |
---|---|
1 | Product A |
2 | Product B |
2 | Product C |
3 | Product D |
As you can see, productID 2 has inconsistent productName: Product B and Product C
. How do I run query just to detect the inconsistent ones? Eg I want the result to be:
productID | productName |
---|---|
2 | Product B |
2 | Product C |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
存在
,以超过1product> product> productiD
product> productname s:或,对于一个小数据集
productname
s productid 的,中的操作员:Use
EXISTS
to get aproductID
with more than 1productName
s:Or, for a small dataset use aggregation in a subquery which counts the distinct number of
productName
s of eachproductID
, with the operatorIN
: