Create Table table2 (Field3, FieldC);
insert into table2 (Field3, FieldC) Select Field1x, FieldAx from Table1;
insert into table2 (Field3, FieldC) Select Field2y, FieldBy from Table1;

this will put your data in to the new table. I suspect the rowids won't match 
what you want, but you can always order by FieldC to get the order you want.

If the rowids are critical, then do the inserts in to a temp table, then insert 
in to the final table using an order by FieldC.


David


________________________________
 From: Gert Van Assche <ger...@datamundi.be>
To: sqlite-users@sqlite.org 
Sent: Tuesday, May 29, 2012 4:44 PM
Subject: [sqlite] rearranging 2 fields into 1 based on an order indicator in 2 
other fields
 
All,

I have a strange table like this

rowid; Field1x; Field2y; FieldAx; FieldBy
1;     A;       a;       0;       1
2;     B;       b;       4;       2

and I would need this:

rowid; Field3; FieldC
1;     A;      0
2;     a;      1
3;     b;      2
4;     B;      4

So:
- the contents of Field1x and Field2y should go into Field3
- the order in the new table/view depends on values FieldAx and FieldBy
that should go into FieldC
- the order indicator in the first table of Field1x is in FieldAx;  the
order indicator of  Field2y is in FieldBy

I have absolutely no clue how to do this. I hope this is possible.

Thanks for your brains on this.


Gert
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to