怎么写循环语句,比较序号一样的行中,金额不一样的月份(01的二月和三月,02的一月),把数据插入到新的表中?
序号 一月 二月 三月 四月 五月 六月 标识
01 0.00 1,800.00 1,800.00 0.00 0.00 0.00 A
01 0.00 0.00 150.00 0.00 0.00 0.00 B
02 1,000 1,000.00 1,000.00 0.00 0.00 1,000 A
02 0.00 1,000.00 1,000.00 0.00 0.00 1,000 B
序号 一月 二月 三月 四月 五月 六月 标识
01 0.00 1,800.00 1,800.00 0.00 0.00 0.00 A
01 0.00 0.00 150.00 0.00 0.00 0.00 B
02 1,000 1,000.00 1,000.00 0.00 0.00 1,000 A
02 0.00 1,000.00 1,000.00 0.00 0.00 1,000 B
序号 一月 二月 三月 四月 五月 六月 标识
01 0.00 1,800 0.00 1,800.00 0.00 0.00 A
01 0.00 0.00 0.00 150.00 0.00 0.00 B怎么通过SQL发现 二月和四月数据不一样????
select 序号,
case when A=0 then 0 else 1 end as 一月,
case when B=0 then 0 else 1 end as 二月,
case when C=0 then 0 else 1 end as 三月,
case when D=0 then 0 else 1 end as 四月,
case when E=0 then 0 else 1 end as 五月,
case when F=0 then 0 else 1 end as 六月
from (
select 序号,
SUM(case when 标识='A' then 一月 else -一月 end) as A,
SUM(case when 标识='A' then 二月 else -二月 end) as B,
SUM(case when 标识='A' then 三月 else -三月 end) as C,
SUM(case when 标识='A' then 四月 else -四月 end) as D,
SUM(case when 标识='A' then 五月 else -五月 end) as E,
SUM(case when 标识='A' then 六月 else -六月 end) as F
From 表 Group By 序号) as X/*
序号 一月 二月 三月 四月 五月 六月
----- ----- ----- ----- ----- ----- -----
1 0 1 1 0 0 0
2 1 0 0 0 0 0(2 行受影响)
*/2.在程序中比较,就是循环整个表,取出每笔记录中的每个值,上下2条记录比较;自己去实现吧