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
在插入“free_meals_bill”表之前,我想检查每个employee_id 是否只允许打一拳。例如,如果 john(员工 id 123456)已经在 free_meals_bill 中,那么在同一日期,john 数据不应再次插入到“free_meals_bill”表中。
询问:
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