James Powell wrote:
> SELECT MAX(X) AS MaxX, MAX(X)/MIN(X) AS RatioX
>
> does the MAX(X) get calculated twice, or does SQLite identify that it
> is the same number and do it only once?

At least in version 3.8.0.2, it gets calculated only once.

Please note that SQLite can optimize MIN/MAX calculations for indexed
columns (<http://www.sqlite.org/optoverview.html#minmax>), but only for
extremely simple queries.  *If* your X column has an index, you could
speed up your query by moving the MIN/MAX into simple subqueries:

  SELECT (SELECT MAX(X) FROM tab) AS MaxX,
         (SELECT MAX(X) FROM tab) / (SELECT MIN(X) FROM tab) AS RatioX;


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to