日期:2014-05-18 浏览次数:20399 次
create table t1(人名 varchar(10),行号 int,列1 int,列2 int,列3 int) insert t1 select '张三', 1, 12, 231, 23 union all select '张三', 2, 2, 232, 24 union all select '张三', 3, 3, 233, 25 union all select '张三', 4, 4, 234, 26 union all select '张三', 5, 33, 235, 27 union all select '李四', 1, 34, 236, 28 union all select '李四', 2, 22, 237, 29 union all select '李四', 3, 33, 238, 30 union all select '李四', 4, 44, 239, 31 union all select '李四', 5, 38, 240, 32 union all select '王五', 1, 39, 241, 33 union all select '王五', 2, 222,242, 34 union all select '王五', 3, 333,243, 35 union all select '王五', 4, 444,244, 36 union all select '王五', 5, 43, 123, 37 go select 人名,列=sum(列1) from t1 where 行号 in (2,3,4) group by 人名 /* 人名 列 ---- --- 李四 99 王五 999 张三 9 */ go drop table t1