高手,能否帮我优化下面sql查询,表格如下
BeginLog表如下
CompletLog表如下
这二个表通过qqid和matchID作为关联键值,也就是qqid和matchID是唯一性。现在想找到比赛场次数量,matchType(比赛类型)为0的,gameEndType(比赛结束代码)为0的,比赛人次数量。
我写得sql如下:
1. select count(*) from BeginLog,CompletLog where BeginLog.qqid=CompletLog.qqid and BeginLog.matchID=CompletLog.qqid and BeginLog.matchType=0 and CompletLog.gameEndType=0;
耗费3min 43.84sec
2. select count(*) from BeginLog join CompletLog on BeginLog.qqid=CompletLog.qqid and BeginLog.matchID=CompletLog.qqid where BeginLog.matchType=0 and CompletLog.gameEndType=0;
耗费3min 7.33sec