0

I am little new in mysql database. My query is like this and its working fine

SELECT visitor_sent * 100 / visitor_quantity as percentage FROM `tbl_orders` WHERE oid =15

But I want it extend to use percentage variable in where clause but its not working.

SELECT visitor_sent * 100 / visitor_quantity as percentage FROM `tbl_orders` WHERE oid =15 AND percentage < 20

its giving me unknown column percentage error. Let me know if anyone here can help me for correct the query.

Thanks!

Vidhi Sharma
  • 143
  • 6

1 Answers1

2

You need to use HAVING instead of WHERE when you want to check on an alias

SELECT visitor_sent * 100 / visitor_quantity as percentage FROM `tbl_orders` WHERE oid =15 HAVING percentage < 20
Thallius
  • 2,482
  • 2
  • 18
  • 36