AndrewMontana
AndrewMontana

Reputation: 21

Update 1 column from another table

How can I make an update? Here is the code, that's doesnt work. ( three local tables are workable, i can't make the last query using update )

WITH 
allowedIds AS ( 
    SELECT client_id as id FROM cardHistory 
    WHERE ( (now())::date -(date_set)::date )::int > 1095 ),
thirtyPercents AS (
    SELECT a.id, ( ( (card_period[2][1])::date - (card_period[1][1])::date)::double precision / 10 ) * 3 AS percent
    FROM client a, allowedIds b
    WHERE a.id = b.id
 ),
 dataSets AS (
     select a.id, (a.card_period[2][1] + ( (b.percent)::int * interval '1 day' ) ) as newDate
    from client a, thirtyPercents b
    where a.id = b.id
 )

    UPDATE client
    SET a.card_period[2][1] = b.newDate
    FROM dataSets b INNER JOIN client a ON a.id = b.id;

Upvotes: 0

Views: 29

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271003

I think you want this:

UPDATE client
    SET card_period[2][1] = b.newDate
    FROM dataSets d 
    WHERE client.id = d.id;

Note that client is not mentioned twice in the query.

Upvotes: 1

Related Questions