MySQL - Calculating a value from two columns in each row, using the result in a WHERE or HAVING clause
Posted
by
taber
on Stack Overflow
See other posts from Stack Overflow
or by taber
Published on 2012-06-11T03:23:56Z
Indexed on
2012/06/11
4:40 UTC
Read the original article
Hit count: 357
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!
© Stack Overflow or respective owner