--> 测试数据:@tb
declare @tb table([ID] int,[身份证号] int,[姓名] varchar(4),[帐目年月] int,[月工资] int)
insert @tb
select 1,123,'张三',200901,123 union all
select 2,123,'张三',200902,123 union all
select 3,456,'李四',200901,222 union all
select 4,456,'李四',200902,222select * from @tb
where ID in (select min(id) from @tb group by 身份证号) /*
ID 身份证号 姓名 帐目年月 月工资
----------- ----------- ---- ----------- -----------
1 123 张三 200901 123
3 456 李四 200901 222(2 行受影响)
*/
我的是SQL2000。
这种格式的东西该如何得到?
--> 测试数据:@tb
declare @tb table([ID] int,[身份证号] int,[姓名] varchar(4),[帐目年月] int,[月工资] int)
insert @tb
select 1,123,'张三',200901,123 union all --这些是手工的东西
select 2,123,'张三',200902,123 union all
select 3,456,'李四',200901,222 union all
select 4,456,'李四',200902,222select * from @tb
where ID in (select min(id) from @tb group by 身份证号) /*
ID 身份证号 姓名 帐目年月 月工资 --这是生成的代码,复制的
----------- ----------- ---- ----------- -----------
1 123 张三 200901 123
3 456 李四 200901 222(2 行受影响)
*/
http://blog.csdn.net/Limpire/archive/2008/07/07/2623016.aspx