distinct,groupby

對(duì)于distinct,groupby的性能。

  1. 數(shù)據(jù)量非常巨大時(shí)候,比如1000萬(wàn)中有300W重復(fù)數(shù)據(jù),這時(shí)候的distinct的效率略好于group by;
  2. 對(duì)于相對(duì)重復(fù)量較小的數(shù)據(jù)量比如1000萬(wàn)中1萬(wàn)的重復(fù)量,用groupby的性能會(huì)遠(yuǎn)優(yōu)于distnct。
  3. 簡(jiǎn)書(shū)上的一篇博客說(shuō)的不錯(cuò),大家可以穿送過(guò)去看一看傳送門(mén)
    例如、找出所有員工當(dāng)前(to_date='9999-01-01')具體的薪水salary情況,對(duì)于相同的薪水只顯示一次,并按照逆序顯示
    CREATE TABLE salaries (
    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;
  4. SELECT DISTINCT salary FROM salaries WHERE to_date = '9999-01-01' ORDER BY salary DESC
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容