我的数据库中存在这样的数据:
xsname jsname xsbj jsbj
11 bb kjk jkj
11 cc kjk dfd
11 bb kjk jkj
我的意思是想对xsname 和 jsname同时去重的同时 还要把其他的字段显示出来,最终结果是:
11 bb kjk jkj
11 cc kjk dfd
就这些分了、如有指教不胜感激
xsname jsname xsbj jsbj
11 bb kjk jkj
11 cc kjk dfd
11 bb kjk jkj
我的意思是想对xsname 和 jsname同时去重的同时 还要把其他的字段显示出来,最终结果是:
11 bb kjk jkj
11 cc kjk dfd
就这些分了、如有指教不胜感激
use tempdb;
/*
create table tb
(
xsname int not null,
jsname nvarchar(10) not null,
xsbj nvarchar(10) not null,
jsbj nvarchar(10) not null
);
insert into tb(xsname,jsname,xsbj,jsbj)
values
(11,'bb','kjk','jkj'),
(11,'cc','kjk','dfd'),
(11,'bb','kjk','jkj');
*/
select distinct *
from tb;
from
(select rn=row_number() over(partition by xsname,jsname order by getdate()),* from tb) t
where rn=1
11 aa
11 bb
该如何将班级插入呢谢谢
select *
from tb t
where not exists (select 1 from tb where a = t.a and b = t.b and c > t.c)
至于插入
insert into tb(col1,col2,col3...)
select col1,col2,col3... from A
--注意tb表列不能为NULL的。
2.插入时选择列名,根据列名一一匹配