觀注這個問題,這個sql如何寫?(7分)

  • 主题发起人 主题发起人 hurryman
  • 开始时间 开始时间
H

hurryman

Unregistered / Unconfirmed
GUEST, unregistred user!
sql.Add('select a.srf_code,a.srf_name,b.cg_num,b.cg_date,a.srf_unit,a.srf_rmb,a.srf_rmb*b.cg_num as c ') ;
sql.Add('from SRFMAST a join cg_file b on a.srf_code=b.part_no ');
sql.Add('where b.cg_date between '+#39+date1+#39+' and '+#39+date2+#39+' order by a.srf_code');
假如產生如下結果:
0001,sfa,asdf,'10/20/2002','af'asdf,sdf
0001,sfa,asdf,'10/21/2002','af',asdf,sdf
0001,sfa,asdf,'10/22/2002','af',asdf,sdf
0002,few,weffs,'10/20/2002','sdf',sfd,wfwe
0002,few,weffs,'10/21/2002','sdf',sfd,wfwe
0002,few,weffs,'10/22/2002','sdf',sfd,wfwe
...........
而我要的結果是:
0001,sfa,asdf,'10/20/2002','af'asdf,sdf
0002,few,weffs,'10/20/2002','sdf',sfd,wfwe
這個sql如何寫?



 
把 join 改为 left join
 
同意楼上的
 
select distinct from (........)
//把你原来的嵌在里面
 
是要最小的日期?分组MIN(RQ)
 
后退
顶部