对于distinct,groupby的性能。
- 数据量非常巨大时候,比如1000万中有300W重复数据,这时候的distinct的效率略好于group by;
- 对于相对重复量较小的数据量比如1000万中1万的重复量,用groupby的性能会远优于distnct。
- 简书上的一篇博客说的不错,大家可以穿送过去看一看传送门
例如、找出所有员工当前(to_date='9999-01-01')具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示
CREATE TABLEsalaries
(
emp_no
int(11) NOT NULL,
salary
int(11) NOT NULL,
from_date
date NOT NULL,
to_date
date NOT NULL,
PRIMARY KEY (emp_no
,from_date
));
1.select salary
from salaries
where to_date='9999-01-01'
group by salary
order by salary desc71. select salary from salaries where to_date='9999-01-01' group by salary order by salary desc; - SELECT DISTINCT salary FROM salaries WHERE to_date = '9999-01-01' ORDER BY salary DESC