就是用了distinct,它只能查distinct对应的字段哦,如果你写成:eg:select distinct(ebay_id),id,referer    from autoorder order by id的话,那查询的将会是autoorder表中的所有记录,没有做到筛选不同ebay_id的记录但是,如果我用了distinct(ebay_id)来实现筛选不同ebay_id的记录,又需要取出对应的其他字段该怎么写呢?select ebay_id,id,referer from autoorder where ebay_id in (select distinct(ebay_id) from autoorder order by id);
这样用子查询可以吗?或者还有没有其他法子呢?

解决方案 »

  1.   

    select a.ebay_id,a.id,a.referer from autoorder a inner join (select distinct(ebay_id) from autoorder order by id) b on a.ebay_id=b.ebay_id连接
      

  2.   

    select ebay_id,id,referer from autoorder a where (select count(*) from autoorder  where ebay_id=a.ebay_id and (cast(id as varchar)+referer)<=(cast(a.id as varchar)+a.referer))=1
      

  3.   

    select a.ebay_id,a.id,a.referer from autoorder a where exists(select distinct(ebay_id) from autoorder where ebay_id=a.ebay_id)
      

  4.   

    无论怎样,只要记录之间这三个字段有一个不同,用distinct也过滤不了
      

  5.   

    除非是相同的ebay_id只取一条记录
      

  6.   

    这个问题本身就有点问题用了distinct(ebay_id)来实现筛选不同ebay_id的记录,又需要取出对应的其他字段该怎么写呢?比如ebay_id为1的时候,有2条记录,distinct ebay_id就为1,但是两条记录,怎么可能在一条记录里体现出来呢,逻辑就有问题嘛