I have the following table structures:
Course(course_id, course_name, language, course_price, create_date, average_rating, category, course_description, certificate_price, course_creator_id)
Person(person_id, username, email, name, surname, password, date_of_birth)
Discount(discount_id, discounted_course_id, allower_course_creator_id, is_allowed, start_date, end_date, percentage)
When I try to filter the courses whose price is >= 10, I wrote price >= 10 because in the SELECT clause, there is CASE-ELSE statement which ends with "AS price".
Why do I get "Unknown column 'price' in 'where clause'" error when I query this string?
SELECT C.course_id, C.course_name, C.language, C.average_rating,
C.category, P.name, P.surname, D.percentage,
D.start_date, D.end_date, D.is_allowed,
(CASE WHEN CURRENT_DATE <= D.end_date AND CURRENT_DATE >= D.start_date AND D.is_allowed THEN
C.course_price * (( 100 - D.percentage ) / 100) ELSE C.course_price END) as price
FROM course C LEFT OUTER JOIN discount D ON C.course_id = D.discounted_course_id
LEFT JOIN person P ON
C.course_creator_id = P.person_id WHERE price >= 10
AND average_rating >= '30' AND average_rating <= '40' AND language = 'English'
AND category = 'Finance'
I want to filter according to the price, however, this way, I get the error.