我这是有一些客户订单的数据,我想查出在一个时间段内的客户订单是不是有重复的,其下重了的,要怎么做?条件也就是把客户的名字一样,并且产品编号也一样的显示出来我做了一个临时表C,把要用的字段全放入其中select * from c where fcustid in (Select fcustid From dbo.SEOrder Where Group by fcustid having count(*)>1) amd (fdate between '2009-08-15' And '2009-08-16')ORDER BY fcustid DESC我现在的问题是如何查出产品编号也一样的订单
也就是把名字相同且产品编号也相同的订单数据显示出来

解决方案 »

  1.   

    SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE 名字=T.名字 AND 编号=T.编号)
    AND TIME ...
      

  2.   

    select * from tb t join tb a where t.id=b.id and t.orderid=b.orderid
    ?
      

  3.   

    select *
    from tb t
    where exists(select 1 from 名字=t.名字 and 产品编号=t.产品编号 and fdate!=t.fdate)
      

  4.   


    select 客户名称,订单编号 from c group by 客户名称,订单编号 having(count(*)>1)至于怎么处理,就看你的要求了
      

  5.   

    SELECT * FROM TB T 
    WHERE EXISTS(SELECT 1 FROM TB WHERE 名字=T.名字 AND 编号=T.编号 AND TIME<>T.TIME)
    AND TIME BETWEEN '2009-08-15' And '2009-08-16' 
    这样应该好点
      

  6.   

    select *
    from tb t
    where exists(select 1 fromtn where 名字=t.名字 and 产品编号=t.产品编号 and fdate!=t.fdate)
      

  7.   

    select 你要的字段
    from dbo.SEOrder x
    where exists (Select 1 From dbo.SEOrder 
    Where fcustid = x.fcustid and fdate between '2009-08-15' And '2009-08-16'
    and 产品编号 = x.产品编号 and 订单编号<> x.订单编号
    )
    and fdate between '2009-08-15' And '2009-08-16'
    ORDER BY fcustid DESC 
      

  8.   

    表SEOrder 订单表 中的
      fcation 客户代码和
    表Item    客户信息表
      fcation 对应为了得到客户的名字并显示
    而SEOrder 中的fiterid和表SEOrderEntry中的fiterid对应为了得到产品代码我最后想要的就是查出订单中在一个时间段内下重了的订单并显示出来
    也就是说客户名字和产品代码同时相同就说明可以下重了,只要把他显示出来就行
      

  9.   

    这是我前面做的可以差出在一个时间段内的名字相同的订单
    select * from c where fcustid in (Select fcustid From dbo.SEOrder Where Group by fcustid having count(*)>1) amd (fdate between '2009-08-15' And '2009-08-16')ORDER BY fcustid DESC 
    但是我还要再筛选一下名字相同是其一产品代码也要相同,才是最后结果
      

  10.   

    select * INOT #TT from c 
    where fcustid in (Select fcustid From dbo.SEOrder Where Group by fcustid having count(*)>1) amd (fdate between '2009-08-15' And '2009-08-16')ORDER BY fcustid DESC SELECT * FROM #TT T 
    WHERE EXISTS(SELECT 1 FROM #TT WHERE 名字=T.名字 AND 编号=T.编号 AND TIME<>T.TIME)那这样吧
      

  11.   

    7哥
    刚才我问了一个就是id,col相同的,用这种好像不行
    不是count(1)..>1吗?
      

  12.   

    没有参考的列是不行的,呵呵加了个TIME列呀,如果没有的话只能按你那帖了,
      

  13.   

    都是用and 连接的
    两个,三个不一样吗?
      

  14.   

    select * from c where( c.fcustid,c.productNumber) in (Select fcustid,productNumber From dbo.SEOrder Where Group by fcustid,productNumber having count(*)>1) and (fdate between '2009-08-15' And '2009-08-16')ORDER BY fcustid DESC