The table TEST is wrong because it has duplicate values.
(表TEST是错误的,因为它具有重复的值。)
I need to update the relational table with an unique id for test and then delete the duplicated values. (我需要使用唯一的ID更新关系表以进行测试,然后删除重复的值。)
TEST
(测试)
+----------+---------+
| id_test | name |
+----------+---------+
| 1 | gir |
| 2 | gir |
| 3 | gir |
| 4 | ego |
| 5 | ego |
| 6 | iph |
| 7 | iph |
+----------+---------+
PRODUCT_HAS_TEST
(PRODUCT_HAS_TEST)
+----------+---------+
| id_prod | id_test |
+----------+---------+
| 3 | 1 |
| 1 | 2 |
| 2 | 2 |
| 4 | 3 |
| 5 | 4 |
| 6 | 5 |
| 7 | 6 |
| 8 | 7 |
+----------+---------+
I have this query to find duplicate values:
(我有此查询以查找重复的值:)
SELECT GROUP_CONCAT(id_test) as ids, name, COUNT(*) c FROM test GROUP BY name HAVING c > 1;
Result:
(结果:)
+------+------+------+
| ids | name | c |
+------+------+------+
| 4,5 | ego | 2 |
|1,2,3 | gir | 3 |
| 6,7 | iph | 2 |
+------+------+------+
And another one to delete duplicate values from TEST:
(另一个从测试中删除重复值的方法:)
delete
from test using test,
test e1
where test.id > e1.id
and test.name = e1.name
But I need to update the table PRODUCT_HAS_TEST first and I don't know how to do it.
(但是我需要先更新表PRODUCT_HAS_TEST,但我不知道该怎么做。)
Expected result:
(预期结果:)
PRODUCT_HAS_TEST
(PRODUCT_HAS_TEST)
+----------+---------+
| id_prod | id_test |
+----------+---------+
| 3 | 1 |
| 1 | 1 |
| 2 | 1 |
| 4 | 1 |
| 5 | 4 |
| 6 | 4 |
| 7 | 6 |
| 8 | 6 |
+----------+---------+
TEST
(测试)
+----------+---------+
| id_test | name |
+----------+---------+
| 1 | gir |
| 4 | ego |
| 6 | iph |
+----------+---------+
ask by Giulia translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…