查重復的記錄:select a,b,c from table group by a,b,c having count(*)>1
是因为时间的问题,用 convert(varchar(10),DT,120)
--大家有没有看清楚,楼主的info字段是ntext--而ntext根本就不支持distinct--先不管楼主的语句是否能达到效果,至少语句要能执行啊--测试 create table Table1(name char(10),info ntext,Dt datetime) go--查询方式1(楼主自己的) select distinct info,name,Dt from Table1 where name<>'' and info <>'' order by Dt go--查询方式人(progress99(如履薄冰)的) select name,info,dt from table1 group by name,info,dt having count(*)>1 go--删除测试环境 drop table Table1/*--测试结果 服务器: 消息 8163,级别 16,状态 3,行 3 不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。 服务器: 消息 306,级别 16,状态 2,行 3 不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。 --*/
没错,text,ntext,image这些字段也不可能作group地
已经将ntext改成char型了,请指教
select info,name,Dt=max(dt) from Table1 where name<>'' and info <>'' group by Dt
你所谓的重复是指什么? info相同就算重复,还是 info+name相同就算重复
我的info字段有重复记录的,按你写的还是有重复记录
--写错了,改:select info,name=max(name),Dt=max(dt) from Table1 where name<>'' and info <>'' group by info order by dt
from table
group by a,b,c
having count(*)>1
create table Table1(name char(10),info ntext,Dt datetime)
go--查询方式1(楼主自己的)
select distinct info,name,Dt from Table1 where name<>'' and info <>''
order by Dt
go--查询方式人(progress99(如履薄冰)的)
select name,info,dt
from table1
group by name,info,dt
having count(*)>1
go--删除测试环境
drop table Table1/*--测试结果
服务器: 消息 8163,级别 16,状态 3,行 3
不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。
服务器: 消息 306,级别 16,状态 2,行 3
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
--*/
from Table1
where name<>'' and info <>''
group by Dt
from Table1
where name<>'' and info <>''
group by info
order by dt