日期:2014-05-19  浏览次数:20402 次

求一对多查询语句写法
表A   记录   aa   bb
表B   记录   cc   dd
aa和cc一对多,
查询   select   bb,dd  

表A不要出现多次,就是表A对应的表B只要第一条


------解决方案--------------------


Select
A.bb,
Max(B.dd) As dd
From
A
Left Join
B
On A.aa = B.cc
Group By
A.bb
------解决方案--------------------
select bb,(select top 1 dd from b where b.cc=a.aa) as dd from a
------解决方案--------------------
select bb,dd
from 表A,(select top 1 cc,dd from 表B)表B
where 表A.aa=表B.cc
------解决方案--------------------
select bb,dd from (select a.*,b.* from aa,bb where a.aa=b.cc) t group by bb
------解决方案--------------------
更正一下:
select bb,min(dd) from (select a.*,b.* from aa,bb where a.aa=b.cc) t group by bb