tbl1
type1 type2 model
id1 id2 model1tbl2
type1 type2 value createdate
id1 id2 value1 2007-1-1
id1 id2 value2 2007-1-2我想得到
model type1 type2 value
model1 id1 id2 value2
left join
我直接写的
select * from tbl1
left join tbl2 on tbl1.type1=tbl2.type1 and tbl1.type1=tbl2.type2
where model=model1重复记录了
type1 type2 model
id1 id2 model1tbl2
type1 type2 value createdate
id1 id2 value1 2007-1-1
id1 id2 value2 2007-1-2我想得到
model type1 type2 value
model1 id1 id2 value2
left join
我直接写的
select * from tbl1
left join tbl2 on tbl1.type1=tbl2.type1 and tbl1.type1=tbl2.type2
where model=model1重复记录了
left join tbl2 on tbl1.type1=tbl2.type1 and tbl1.type1=tbl2.type2
where model=model1
left join tbl2 on tbl1.type1=tbl2.type1 and tbl1.type1=tbl2.type2
group by tbl1.model,tbl1.type1,tbl1.type2
type1 type2 model
id1 id2 model1tbl2
type1 type2 value createdate
id1 id2 value1 2007-1-1
id1 id2 value2 2007-1-2我想得到
model type1 type2 value
model1 id1 id2 value2select *,(select max(value) from tab2 b where b.ty1=a.ty1 and b.ty2=a.ty2) from tab1 a
select *,
(select top 1 value from tab2 b where b.type1 =a.type1 and b.type2 =a.type2
order by createdate desc)
from tab1 a
select a.* from tbl1 a
left join
(select * from tbl2 b
where not exists(select * from tbl2 where type1=b.type1 and type2=b.type2 and createdate>b.createdate))c
on c.type1 =a.type1 and c.type2 =a.type2
为什么一定要用left join~~~快吗???还是你想知道left join实现
可是当你原来的sql语句比较复杂,而你现在只是要增加一个表某个字段的关联判断;
这时,你还要修改为更加庞大的子查询吗?
——凡事都不能说绝对啊!!!
大哥~~~~我2007-2-9 11:46:13 发的言你就别2007-07-04 10:57:56 说啦~~~~~人~每天都在进步~~每天都是每天的样子。。
-----如果自己会写~~那就用各种方式写一遍~~哪个快用哪个~~~不要活在一个死角里