在sql2005环境下,有一张物料采购价格表t1的数据需要处理,
字段 物料编码 matid,年份 year,月份month,price 价格
处理要求:当某月采购价格是0,就取到前面月份的不为零的采购价格
求sql处理脚本
补充下 比如:
A 物料 2010年 1月 15.90
A物料 2010年 2月 0
B物料 2010年 2月 20.10
A物料 2010年 3月 0
A物料 2011年 1月 29.80比如:第二条记录 A物料 2010年 2月 0
sql处理后 A物料 2010年 2月 15.90
第四条记录处理后 A物料 2010年 3月 0
sql处理后 A物料 2010年 3月 15.90
字段 物料编码 matid,年份 year,月份month,price 价格
处理要求:当某月采购价格是0,就取到前面月份的不为零的采购价格
求sql处理脚本
补充下 比如:
A 物料 2010年 1月 15.90
A物料 2010年 2月 0
B物料 2010年 2月 20.10
A物料 2010年 3月 0
A物料 2011年 1月 29.80比如:第二条记录 A物料 2010年 2月 0
sql处理后 A物料 2010年 2月 15.90
第四条记录处理后 A物料 2010年 3月 0
sql处理后 A物料 2010年 3月 15.90
where matid=a.matid and price<>0 and [year]=a.[year] order by [month] desc)
from tb a where price=0