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 来计算非重复结果的数目。
(
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 来计算非重复结果的数目。
相关文章推荐
- SQL COUNT DISTINCT 函数
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg - YJingLee's Blog - 博客园(转)
- LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- SQL COUNT DISTINCT 函数
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- 查询所有订单的最新信息的SQL语句的写法 DISTINCT配合count和group by一起完成
- SQL(select distinct count)
- Hive SQL优化之 Count Distinct
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- SQL count distinct与NULL
- LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- LINQ体验(5)--LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- SQL Server select count(distinct *)
- SQL 中 Count 和Distinct的使用
- SQL Server distinct top count 查询
- LINQ体验(5)——LINQ to SQL语句之Select/Distinct和Count/Sum/Min/Max/Avg
- SQL Server distinct top count 查询