Create a table B with data coming from table A

From: "lhaj(dot)merigh(at)gmail(dot)com" <lhaj(dot)merigh(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Create a table B with data coming from table A
Date: 2007-06-11 21:23:59
Message-ID: 1181597039.682005.104060@k79g2000hse.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

My original table is like that:

ID A1 A2 A3 cnt
1234 1 0 0 4
1234 1 0 1 8
1234 1 1 1 5
1235 1 0 0 6
1235 1 0 1 7
1235 1 1 1 12

I have to create a new table B:

ID B1 B2 B3 S
1234 4 8 5 17
1235 6 7 12 25

The combination (A1=1,A2=0,A3=0) gives B1
The combination (A1=1,A2=0,A3=0) gives B2
The combination (A1=1,A2=1,A3=1) gives B3

S = B1+B2+B3

I think it's a classical problem, but i can't see to problem key

Thx,
Lhaj

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-06-11 22:29:38 Re: trying to track down postgres deaths
Previous Message Erwin Brandstetter 2007-06-11 21:16:47 Re: how to speed up query