其他技术区
group 标签描述

在语义相同,有索引的情况下:groupby和distinct都能使用索引,效率相同。在语义相同,无索引的情况下:distinct效率高于groupby。原因是distinct和groupby都会进行分组操作,但groupby可能会进行排序,触发filesort,导致sql执行效率低下。 二、distinct用法 SELECTDISTINCTcolumnsFROMtable_nameWHEREwhere_conditions; mysql>selectdistinctagefromstudent; +------+ |age| +------+ |10| |12| |11| |NU...

  TEZNKK3IfmPf   2024年04月19日   25   0   0 group索引