0

我有一个 SQL 语句,它看起来像:

select id, CIDs, COLOR, XT, MP, Name, concat(PIDs,",",GROUP_CONCAT(DISTINCT id)) as PIDs, IFNULL(Name,id) as unqName from ( 
select id, CIDs, COLOR, XT, MP, Name, concat(PIDs,",",GROUP_CONCAT(DISTINCT id)) as PIDs, IFNULL(MP,id) as unqMP from (
select id, CIDs, COLOR, XT, MP, Name, concat(PIDs,",",GROUP_CONCAT(DISTINCT id)) as PIDs, IFNULL(XT,id) as unqXT from ( 
select id, CIDs, COLOR, XT, MP, Name, GROUP_CONCAT(DISTINCT id) as PIDs, IFNULL(COLOR,id) as unqCOLOR from Performance group by unqCOLOR 
) m group by unqXT 
) x group by unqMP 
) y group by unqName

我需要修剪性能细节并获取 PID,它可以工作。但是我得到了重复的 PID(4 次),是否有任何性能优化?为了让 SQL 语句更快地执行并且 PID 是唯一的?

mysql> select count(*) from Performance;
+----------+
| count(*) |
+----------+
|   243484 |
+----------+
1 row in set (0.00 sec)

执行的 SQL 语句需要:

Query OK, 137771 rows affected (43.54 sec)

编辑:SQLFiddle 链接:

http://sqlfiddle.com/#!2/e2b12/1/0

4

0 回答 0