MariaDB社区

标题: LEFT JION的用法 [打印本页]

作者: yuanzai32    时间: 2011-11-22 15:11
标题: LEFT JION的用法
SELECT IFNULL(SUM(skt43.skf610),0)-IFNULL(SUM(skt43.skf669),0),
skt57.skf772
FROM skt57
LEFT JOIN (skt43,skt42)
ON (skt43.skf616=skt42.skf587
AND skt57.skf772=skt42.skf589  
AND skt42.skf591=5
AND skt43.skf611>=20110701
AND skt43.skf611<=20110930)
AND skt42.skf597=0
GROUP BY skt57.skf772,skt42.skf590
HAVING skt42.skf590=16;




SELECT IFNULL(SUM(skt43.skf610),0)-IFNULL(SUM(skt43.skf669),0),
skt57.skf772,
FROM skt43,skt42,skt57
WHERE skt43.skf616=skt42.skf587
AND skt57.skf772=skt42.skf589
AND skt42.skf590=16
AND skt42.skf591=5 AND SKT42.SKF597=0
AND skt43.skf611>=20110701
AND skt43.skf611<=20110930
GROUP BY skt57.skf772;


这两个实现的查询结果都是一样的,所以就有疑问了,这两种哪个好,百度了只有讲LEFT JOIN ON和LEFT JOIN WHERE的区别的,越学问题越多呀
作者: kider    时间: 2011-11-23 09:33
用explain看看就知道了
原则上先滤出数据排序比排序后再滤数据效果要好
作者: 永生    时间: 2011-11-23 10:54
用explain看看就知道了




欢迎光临 MariaDB社区 (http://123.56.88.72/) Powered by Discuz! X3.2