Which is the least expensive aggregate function in the absence of ANY()

前端 未结 4 1464
半阙折子戏
半阙折子戏 2020-12-06 17:49

I usally use MAX() or MIN() if a DBMS hasn\'t an ANY() aggregate function.

Is there something less expensive in mySQL and MS-SQL?

4条回答
  •  死守一世寂寞
    2020-12-06 18:18

    MySQL does not need an ANY() aggregate.

    if I do a

    SELECT field1, field2, SUM(field3) FROM table1 
    GROUP BY field2
    

    Microsofts T-SQL will complain but

    MySQL will just silently execute

    SELECT whatever(field1), field2, SUM(.... 
    

    Which of course is way faster than SELECT max(field1), field2, SUM(.... GROUP BY field2

    MySQL supports ANY, but SELECT ANY(field1) ... doesn't work because ANY is an operator similar to IN and ALL.
    see: http://dev.mysql.com/doc/refman/5.0/en/any-in-some-subqueries.html

    I love MySQL

提交回复
热议问题