输入:
Sku开始_月结束_月率1月3日1日4月6日2月2日
输出:Sku月率2010年1月1日2月10日10年3月1日20年4月2日5月2日20年6月2日
从上述输入获得输出的逻辑是什么?
通常的方法是在表中定义月份,就像这样
; with monthsdef as
(select * from
(values ('jan',1), ('feb',2),('mar',3),('apr',4),('may',5),('jun',6),
('jul',7),('aug',8),('sep',9),('oct',10),('nov',11),('dec',12)) as m(monthname,number)
)
select
sku,month=m.monthname, rate
from
yourtable
inner join monthsdef m1
on start_month=m1.monthname
inner join monthsdef m2
on end_month=m2.monthname
right join monthsdef m
on m.number between m1.number and m2.number