select * from table1 where dealdate =(select max(dealdate) from table1 where city='天津') 这样查询会有一条数据,city为天津,区县和商圈都为空district comarea
下面这两条sql语句,差别在于第一条把table1的 时间筛选放到里面当做表a,第一条是执行的right join 第二条语句看执行计划的是 inner join ,如果把 b.city=‘天津’ 改为a.city='天津' 也会导致right join执行的是inner join
select b.district,a.dealdate from (select * from table1 where dealdate =(select max(dealdate) from table1 where city='天津')) a right join table2 b with(nolock) on a.city=b.city and a.district=b.district and a.comarea=b.commerce where b.city='天津' and b.samplingtime=(select max(samplingtime) from table2 where city='天津')
select b.commerce,a.dealcount from table1 a with(nolock) right join table2 b with(nolock) on a.city=b.city and a.district=b.district and a.comarea=b.commerce where b.city='天津' and a.dealdate =(select max(dealdate) from table1 where city='天津') and b.samplingtime=(select max(samplingtime) from table2 where city='天津') 我想知道原因,请大家不吝赐教,可简单说下原理或者可以指出某书的某章节 或者 百度应该怎么搜索 可以解答此问题.另外 没有系统学习过数据库,请大家推荐一本合适的书,
http://news.cnblogs.com/n/171861/