首页 新闻 会员 周边

请教一个mssql 右连接的问题

1
悬赏园豆:100 [已关闭问题] 关闭于 2016-07-18 09:41

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='天津') 我想知道原因,请大家不吝赐教,可简单说下原理或者可以指出某书的某章节 或者 百度应该怎么搜索 可以解答此问题.另外 没有系统学习过数据库,请大家推荐一本合适的书,

 

厕所里的臭石头的主页 厕所里的臭石头 | 初学一级 | 园豆:108
提问于:2016-07-07 12:10
< >
分享
所有回答(1)
0

http://news.cnblogs.com/n/171861/

萧萧弈寒 | 园豆:170 (初学一级) | 2016-07-08 10:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册