I have a very large table in an SQLite database that I need to convert from a multiple column format to a multiple row format. I need something that I can do at run-time, because the database already exists on the user's end and the best I can do is get the existing data and reformat it in a more useable structure.
Here's what the data looks like now....
Part Sales-Mth1 Sales-Mth2 Sales-Mth3 Fcst-Mth1 Fcst-Mth2 Fcst-Mth3
ABC 100 200 300 150 250 350
DEF 50 50 50 60 60 60
GHI 10 20 30 40 50 60
JKL 25 35 25 35 25 35
And here's what I need to convert it to...
Part Type Date Value
ABC Sales Mth1 100
ABC Sales Mth2 200
ABC Sales Mth3 300
ABC Fcst Mth1 150
ABC Fcst Mth2 250
ABC Fcst Mth3 350
DEF Sales Mth1 50
DEF Sales Mth2 50
DEF Sales Mth3 50
DEF Fcst Mth1 60
DEF Fcst Mth2 60
DEF Fcst Mth3 60
GHI Sales Mth1 10
GHI Sales Mth2 20
GHI Sales Mth3 30
GHI Fcst Mth1 40
GHI Fcst Mth2 50
GHI Fcst Mth3 60
JKL Sales Mth1 25
JKL Sales Mth2 35
JKL Sales Mth3 25
JKL Fcst Mth1 35
JKL Fcst Mth2 25
JKL Fcst Mth3 35
Is this even possible with a single SQL statement?
WATYF
Aucun commentaire:
Enregistrer un commentaire