a表:(时间)
| date |
| 19990101 |
| 19990102 |
| ... |
| 20000101 |
| startdate | enddate | credit |
| 19980901 | 19990201 | aaa |
| 19990201 | 19990302 | aa |
| ... | ... | ... |
| 19990903 | null | baa |
我很菜,只会先把两者cross join,然后算出一个flag变量来判断date是否在区间中。请问有什么更有效的办法?
我的方法:
select * from
(
select a.data, b.credit,
case
when a.date > =b.startdate and ( a.date <=b.enddate or b.enddate is null) then '1'
else '0'
end as flag
from a cross join b
) c
where c.flag='1'



雷达卡


京公网安备 11010802022788号







