SQL COUNT DISTINCT

Create table trade

(

  sell_id int,  --卖家

  buy_id int, -- 卖家

      time date --交易时间

)

 

sell_id, buy_id, time

s1, b2, 2013-1-1

s1, b3, 2013-1-1

s1, b2, 2013-1-2

s2, b4, 2013-1-2

 

select sell_id, count(buy_id) from trader group by sell_id

结果是:  s1, 3

             s2, 1

select count(distinct buy_id) from trader group by sell_id

结果是:s1, 2

           s2, 1

 

总结: count distinct 来计算非重复结果的数目。

posted @ 2014-04-04 11:04  忍者职业  阅读(164)  评论(0)    收藏  举报