Re: insert only if conditions are met? - Mailing list pgsql-sql

From Chris Travers
Subject Re: insert only if conditions are met?
Date
Msg-id 4315DD76.40504@metatrontech.com
Whole thread Raw
In response to Re: insert only if conditions are met?  (Henry Ortega <juandelacruz@gmail.com>)
List pgsql-sql
Henry Ortega wrote:

> What I am trying to do is
> * Insert a record for EMPLOYEE A to TABLE A
> IF
> the sum of the hours worked by EMPLOYEE A on TABLE A
> is not equal to N
>
> Is this possible?

Yes, but we will need to see your database schema to provide examples.

A simple example might be
INSERT INTO table_a
SELECT firstname, lastname FROM table_b
WHERE table_b IN (SELECT id FROM (SELECT id, sum(labor) as total_hours
from table_c group by id) WHERE total_hours <> n);

Best Wishes,
Chris Travers
Metatron Technology Consulting

Attachment

pgsql-sql by date:

Previous
From: Tino Wildenhain
Date:
Subject: Re: [GENERAL] How do I copy part of table from db1 to db2 (and
Next
From: "Akshay Mathur"
Date:
Subject: Re: sql function: using set as argument