Created
February 18, 2013 09:38
-
-
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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