您的位置:首页 > 数据库

SQL COUNT DISTINCT

2014-04-04 11:04 330 查看
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 来计算非重复结果的数目。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: