Skip to content

Instantly share code, notes, and snippets.

@jiceb
Created February 18, 2013 09:38
Show Gist options
  • Select an option

  • Save jiceb/4976230 to your computer and use it in GitHub Desktop.

Select an option

Save jiceb/4976230 to your computer and use it in GitHub Desktop.
AVG, MAX, MIN on meta_value in WordPress If you want to do MAX, MIN, AVG or other kind of mathematical operation on non-numeric MySQL columns (such as longtext for meta_value in WordPress), you can cast it to float like this:
/*
AVG, MAX, MIN on meta_value in WordPress
http://konstruktors.com/blog/wordpress/4554-avg-max-min-meta-value/
*/
SELECT
meta_key,
MAX(meta_value+0.0) max_meta
FROM
postmeta
WHERE
meta_key='your_key'
GROUP BY
meta_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment