K kmchen Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-18 #1 A、B两表。A表和B表通过一关键字段C相关a.c=b.c。A表每一记录在B表都有多条记录对应。需要得到A表每一条记录和B表中字段D为最小值的那条关联记录。怎么解。<br>谢谢大家。
G guqiu Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-18 #2 select a.Field1,a.Field2,min(b.D) D from A a<br>left join B b on(b.C=a.C)<br>where XXXXXXX<br>group by a.Field1,a.Field2<br>-------不知道这样行不行
select a.Field1,a.Field2,min(b.D) D from A a<br>left join B b on(b.C=a.C)<br>where XXXXXXX<br>group by a.Field1,a.Field2<br>-------不知道这样行不行
F fas2000 Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-18 #3 前面几天刚解决此问题 <br><br>select a.*,B.* from A join b on a.c=b.c and b.d=(select min(d) from b where b.c=a.c)<br><br>应该可以解决你的问题
前面几天刚解决此问题 <br><br>select a.*,B.* from A join b on a.c=b.c and b.d=(select min(d) from b where b.c=a.c)<br><br>应该可以解决你的问题
J Jaby Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-19 #6 楼主,提这样的问题.居然敢说自己不是新手....这是SQL的基础哦!
F fas2000 Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-20 #8 此问题真得有点迷惑人的!<br> b.d=(select min(d) from b where b.c=a.c)<br>开始这里还真没想通
D DIGUA Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-20 #9 楼主这样写即可,可以就结帖吧<br>select a.*,b.* from a,b <br>where a.c=b.c and b.d in(select min(d) from b group by c)
楼主这样写即可,可以就结帖吧<br>select a.*,b.* from a,b <br>where a.c=b.c and b.d in(select min(d) from b group by c)
K kmchen Unregistered / Unconfirmed GUEST, unregistred user! 2008-05-20 #11 非常感谢各位朋友。fas2000的语句需要加group by 语句。谢谢。分给少了。我以为给的是200分。呵呵。sorry