I have employees, i need to create a new column, which will say, that this employee deserves a reward if he has placed more than 60 orders. How make this?
Create VIEW Award_1997 AS
Select employee_id, last_name, first_name, order_date
From orders
Join employees using (employee_id)
Select first_name, last_name, count(employee_id) as orders_count
From Award_1997
Where order_date >= '1997-01-01' and order_date <='1997-12-31'
Group by first_name, last_name
Having count(employee_id) > 60 -- if > 60 4 column = yes otherwise no
>Solution :
Your friend here is the CASE statement
CASE WHEN condition THEN result
[WHEN ...]
[ELSE result]
END
https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-CASE
CASE WHEN COUNT(employee_id) > 60 THEN 'YES'
ELSE 'NO'
END AS "COLUMN_NAME"