标题: left join的奇怪问题 [打印本页] 作者: shiyiming 时间: 2004-9-3 23:46 标题: left join的奇怪问题 表a: code,crdt,crtm,id(说明:code为产品代码,crdt为日期,crtm为时间,id是一外关键字,稍后做计数用)
表b:code,start_date,start_time,end_date,end_time(各字段意义不言而喻)
目标:按照b中开始结束日期时间来计算code的个数(即count(id))
现语句如下:
proc sql noprint;
create table test as
select a.code,b.start_date,b.start_time,b.end_date,b.end_time,
count(id) as cc
from a left join b
on a.code=b.code and
a.crdt>=b.start_date and a.crtm>=b.start_time and
a.crdt<=b.end_date and a.crtm<b.end_time
quit;