0

how to SELECT rows based on the calculated value field from the same table?

table A

-----------------------
|id   | col2  | col3  |
---------------------
| 1   |  23   |  33   |
| 2   |  33   |  24   | 
| 3   |  11   |  4    |

I have tried

SELECT id, (col2 + col3) as NV WHERE NV > 50 

Unfortuantely, can't get it workig... Thanks for help...

m1k3y3
  • 2,762
  • 8
  • 39
  • 68

1 Answers1

3

You cannot use an alias in a where clause at the same level as the select where it is defined.

MySQL has an extension that allows you to use the having clause for this purpose:

SELECT id, (col2 + col3) as NV 
FROM . . . 
HAVING NV > 50 ;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786