查询执行得很慢?

时间:2019-07-17 08:56:04

标签: mysql

我有一个表,其中有四个列ID,MID,SID和Amt,我准备查询以使用级别对amt的总和进行计数。

赞:

SELECT Sum(amt) as level1 FROM adm where sid='MT00001';

SELECT Sum(amt) as level2 FROM adm where sid in (SELECT mid FROM adm where sid='MT00001');

SELECT Sum(amt) as level3 FROM adm where sid in (SELECT mid FROM adm where sid in (SELECT mid FROM adm where sid='MT00001'));

SELECT Sum(amt) as level4 FROM adm where sid in (SELECT mid FROM adm where sid in (SELECT mid FROM adm where sid in (SELECT mid FROM adm where sid='MT00001')))

但是花了很多时间,我想一直到第15级

1 个答案:

答案 0 :(得分:0)

EXPLAIN [your query here]

这将帮助您了解查询和表的当前状态。

在表上添加索引将有助于提高查询性能。