Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to add postscript if condition is met

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

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading