蚂蚁的:去除重复值
如果有ID字段,就是具有唯一性的字段delect table where id not in (  select max(id) from table group by col1,col2,col3...
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,如果是判断所有字段也可以这样
  select * into #aa from table group by id1,id2,....
  delete table 
  insert into table 
  select * from #aa3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
delect # where id not in (
  select max(id) from # group by col1,col2,col3...)
delect table
inset into table(...)
   select ..... from #temp
col1+','+col2+','...col5 联合主键
select * from  table where col1+','+col2+','...col5 in (  select max(col1+','+col2+','...col5) from table 
where having count(*)>1
group by col1,col2,col3,col4 
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
select identity(int,1,1) as id,* into #temp from tabel
select * from  #temp where id in (
  select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)

解决方案 »

  1.   

    select * from product tem where pbclassid=(select min(pbclassid) from product where productid=tem.productid)
      

  2.   

    Select top 15 a.* from product a
    join (select pbclassid,min(productid) as productid from product group by pbclassid) b
    on a.productid = b.productid
    order by ptime desc
      

  3.   

    select top 15 * from product tem where pbclassid=(select min(pbclassid) from product where productid=tem.productid)
      

  4.   

    select * from product a where productid=(select min(productid) from product where pbclassid=a.pbclassid)
      

  5.   

    select top 15 * from product a where productid=(select min(productid) from product where pbclassid=a.pbclassid) 
    order by ptime desc
      

  6.   

    我是想 select 15条记录不是要改变表的结构
    请问大侠该怎么做
      

  7.   

    不需要select top 15 * from product tem where pbclassid=(select min(pbclassid) from product where productid=tem.productid) order by ptime desc即可
      

  8.   

    我看楼主的意思应该是:
    select top 15 * from product a where productid=(select min(productid) from product where pbclassid=a.pbclassid) 
    order by ptime desc
    或:
    Select top 15 a.* from product a
    join (select pbclassid,min(productid) as productid from product group by pbclassid) b
    on a.productid = b.productid
    order by ptime desc
      

  9.   

    re pengdali(大力 V3.0):select top 15 pbclassid,productid,ptime from product tem where pbclassid=(select min(pbclassid) from product where productid=tem.productid) order by ptime desc
    pbclassid   productid   ptime                                                  
    ----------- ----------- ------------------------------------------------------ 
    234         409         2003-10-08 08:55:41.983
    16          327         2003-10-08 08:45:41.327
    222         72          2003-10-07 14:51:36.013
    239         549         2003-10-07 12:23:07.153
    239         551         2003-10-07 12:21:47.670
    239         550         2003-10-07 12:17:53.687
    206         93          2003-10-07 11:27:45.217
    222         548         2003-10-07 10:52:09.687
    222         246         2003-10-07 10:45:40.640
    221         547         2003-10-07 10:41:26.500
    224         546         2003-10-07 10:36:16.090
    222         545         2003-10-07 10:33:19.903
    222         544         2003-10-07 10:30:25.123
    236         543         2003-10-07 09:51:37.280
    28          542         2003-10-06 22:53:57.170(所影响的行数为 15 行)
    pbclassid还是重复的呀
      

  10.   

    select top 15 pbclassid,productid,ptime from product tem where productid=(select min(productid) from product where pbclassid=tem.pbclassid) order by ptime desc
      

  11.   

    或:select top 15 pbclassid,productid,ptime from product tem where ptime=(select min(ptime) from product where pbclassid=tem.pbclassid) order by ptime desc
      

  12.   

    select top 15 pbclassid,productid,ptime from product o,(select pbclassid,min(productid) productid  from product group bypbclassid) s
    where o.pbclassid=s.pbclassid o.productid=s.productid 
    order by ptime desc
      

  13.   

    错了,不重复的是pbclassid
    select top 15 pbclassid,productid,ptime from product o,(select min(pbclassid) pbclassid,productid from product group by productid) s
    where o.pbclassid=s.pbclassid o.productid=s.productid 
    order by ptime desc
      

  14.   

    小补丁
    select top 15 o.pbclassid,o.productid,o.ptime from product o,(select min(pbclassid) pbclassid,productid from product group by productid) s
    where o.pbclassid=s.pbclassid o.productid=s.productid 
    order by ptime desc
      

  15.   

    select  pbclassid,min(productid) as productid,min(ptime) as ptime from product group by pbclassid
      

  16.   

    用 Dennis618(突破平凡) 的吧,我没写and,没测试就是不行
      

  17.   

    回复人: txlicenhe(马可) 
    不好意思!刚刚看到
    你的方法为什么今天的数据看不到呀
    只能插昨天的吗?
      

  18.   

    select top 15 pbclassid,productid,ptime from product tem where ptime=(select min(ptime) from product where pbclassid=tem.pbclassid) order by ptime desc有错?
      

  19.   

    这样看看:
    select top 15 pbclassid,productid,ptime from product tem where productid=(select max(productid) from product where pbclassid=tem.pbclassid) order by ptime desc
    提示什么?
      

  20.   

    select  字段,count(字段) from 表 group by 字段 having count(*)>=2