第一种写法:
select sum(a.weight) as WeightCount,sum(a.amount)as Amount
from vege_pf_out as a left join market_code as c on a.node_id=c.Market_ID
where a.m_rq>='2013-05-01' and a.m_rq<'2013-06-01' and a.node_name like '%批发市场%' and c.isuse='1'
group by a.node_id
第二种写法:
select sum(a.weight) as WeightCount,sum(a.amount)as Amount
from vege_pf_out as a,market_code as c
where a.m_rq>='2013-05-01' and a.m_rq<'2013-06-01' and a.node_name like '%批发市场%' and c.isuse='1' and a.node_id=c.Market_ID
group by a.node_id
一个是用了join ,另一个只用where ,第一种写法和第二种写法有区别吗?还有where后面的条件怎么放,才最省时间。
------解决方案--------------------
2008之前,where条件的列顺序最好和索引的定义顺序一样(假设索引是复合索引),2008开始没有这个限制
------解决方案--------------------
both,但是,建复合索引时,选择度高的应该在前列,因为统计信息只存放第一列的直方图
------解决方案--------------------
单从这个题目的效果,两种写法应该没有区别,因为引用的字段都是自定义字段,
如果从语法角度上说,左连接是不限制左表,只要引用了左表的字段,不管它满不满足连接条件,也就是右表中对应的连接值是否匹配,所有引用字段都要在查询结果中显示出来,不满足条件的,左表对应字段值用null填充,where 连接实际是筛选条件,与inner join相同,个人觉得where 和 inner join应该有细微区别,只是我也没搞清楚
