mySQL Optimize Statement Group By和Subquery

时间:2013-10-30 19:30:27

标签: mysql group-by subquery

我有一个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次),是否有任何性能优化? 为了更快地执行SQ​​L语句并且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

0 个答案:

没有答案