2012-02-27 119 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