I have a MySQL db schema like so:
id flags views done
-------------------------------
1 2 20 0
2 66 100 0
3 25 40 0
4 30 60 0
... thousands of rows ...
I want to update all of the rows whose flags / views are >= 0.2. First as a test I want to try to SELECT to see how many rows would actually get updated. I tried:
SELECT flags/views AS poncho FROM mytable HAVING poncho > 0.2
But this only returns like 2 rows and I know there should be a lot more than that. It seems like it’s calculating the poncho value on all rows or something odd. What am I doing wrong?
Thanks!
Use the
WHEREclause instead ofHAVING:HAVINGaggregates all identical values into one row. The SQL standard would not allow aHAVINGclause without a correspondingGROUP BY, but MySQL is very permissive with the standard. What you have there is effectively the same asMore in the manual here.