SQL查找多行重复项
在我的工作中,我们将数据存储在数据库中,但数据未标准化。我正在寻找一种方法来查找重复的数据。
我们的数据库有 3 行列,名称、状态、策略
该数据可能看起来像这样:
OldTable:
Name | State | Strat
-----+-------+------
A | M | 1
A | X | 3
B | T | 6
C | M | 1
C | X | 3
D | X | 3
我想做的是将数据移动到两个表,一个包含名称,另一个包含状态和策略集,这样它看起来更像这样
NewTable0:
Name | StratID
-----+--------
A | 1
B | 2
C | 1
D | 3
NewTable1:
StratID | State | Strat
--------+-------+------
1 | M | 1
1 | X | 3
2 | T | 6
3 | X | 3
所以在数据示例中 A 和 C 会重复,但 D 不会。我将如何查找和/或识别这些重复项?
At my worki we have data stored in a database, the data is not normalized. I am looking for a way to find what data was duplicated.
Our Data base has 3 rows columns, Name, State, Strategy
This data might looks something like this:
OldTable:
Name | State | Strat
-----+-------+------
A | M | 1
A | X | 3
B | T | 6
C | M | 1
C | X | 3
D | X | 3
What I'd like to do is move the data to two tables, one containing the name the other containing the set of State and Strats so it would look more like this
NewTable0:
Name | StratID
-----+--------
A | 1
B | 2
C | 1
D | 3
NewTable1:
StratID | State | Strat
--------+-------+------
1 | M | 1
1 | X | 3
2 | T | 6
3 | X | 3
So in the data example A and C would be duplicates, but D would not be. How would I go about finding and/or identifying these duplicates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
您可以通过将名称分组在一起并仅列出有多个记录的名称来找到这一点:
应输出:
You could find this out by grouping the Names together, and only listing those where there is more than one record:
Should output: