2012-02-27 61 views
0

可否请您优化下面的mysql查询。mysql query optimizaiton

SELECT COUNT(DISTINCT a.cust_id) as total FROM all_ids AS a LEFT JOIN id_details AS b ON a.cust_id = b.cust_id, users p WHERE (a.status = 'A' or a.status = 'I') and b.cust_id IS NOT NULL and a.type = 'abc' AND a.user_id = p.id AND p.team = 'customers'; 
+1

请提出问题。 – YXD 2012-02-27 10:55:08

+0

呃,你的问题是什么?你想优化什么? – jlemos 2012-02-27 10:55:53

+0

你的问题是什么? – 2012-02-27 10:55:56

回答

2
  1. 您可能需要添加GROUP BY a.useri_id
  2. 与a.status更换(a.status = 'A' 或a.status = 'I')IN( 'A', 'I')
  3. 至于加速它,你需要添加索引到以下列:a.status,a.type,p.team
  4. 也考虑将以下列从字符串更改为整数,可能会使用外部查询表:a.status,a.type,p.team