Table Name: free_meals_bill
punch_date employee_id employee_name product_name
2021-02-22 12:15:50.086471 123456 john Variety Rice - Curd - Rs.35
2021-02-22 12:19:50.086472 234456 marry Variety Rice - Curd - Rs.35
2021-02-22 12:22:50.086473 355456 peter Variety Rice - Curd - Rs.35
Before inserting into "free_meals_bill" table, I want to check that per employee_id only one punch is allowed. For example, if john (employee id 123456) is already in the free_meals_bill then again for the same date, john data should not be insert again into the "free_meals_bill" table.
Query:
insert into free_meals_bill (punch_date,employee_id,employee_name,product_name)
Values ('2021-02-22 10:15:50.086471',123456,'john','Variety Rice - Curd - Rs.35')
SELECT
employee_id,
COUNT(*) as count,
date_trunc('day',punch_date) as day
FROM bill_item
WHERE punch_date>= CURRENT_DATE
GROUP BY employee_id, day
HAVING COUNT(*) = 0