060101012015000001 1 0101 01
060101012015000002 1 0101 01
060101012015000002 2 0101 01
060101012015000003 1 0101 01
新增的数据的POLICYNO = 060101012015000002 ITEMNO是POLICYNO = 060101012015000002的数据的最大值+1其他字段和当前ITEMNO最大值 的那条数据的值一样 要怎么写,求大佬帮忙
1 个解决方案
#1
insert into tablename
select '060101012015000003',t1.ITEMNO,t1.RISKCODE,t1.ITEMCODE
from tablename t1,
(select POLICYNO, max(ITEMNO)as itemno from tablename group by POLICYNO ) t2
where t1.POLICYNO = t2.POLICYNO and t1.ITEMNO = t2. ITEMNO and t1.POLICYNO = '060101012015000002'
#1
insert into tablename
select '060101012015000003',t1.ITEMNO,t1.RISKCODE,t1.ITEMCODE
from tablename t1,
(select POLICYNO, max(ITEMNO)as itemno from tablename group by POLICYNO ) t2
where t1.POLICYNO = t2.POLICYNO and t1.ITEMNO = t2. ITEMNO and t1.POLICYNO = '060101012015000002'