All;
I have a need to create a view. The data table does not exist yet, the
question is on how to best set it up in postgres. The resulting view
has to be spreadsheet-like, and will be loaded directly via ODBC into
Excel for number crunching. Maybe something like:
Report Type #1
|
Date
|
Location 1
|
Location 2
|
Location 3
|
Location 4
|
Jan 2006
|
5
|
77
|
23
|
233
|
Feb 2006
|
7
|
556
|
233
|
269
|
March 2006
|
8
|
5666
|
1024
|
100
|
I could mirror that exact structure in a SQL table, but I'd loose the
relation (since the column headings actually refer to an associated
table).
Now if I were just working in pure SQL, I'd build it in a relational
manner, with a long series of rows:
report_type
|
date
|
xx_location
|
value
|
1
|
Jan 2006
|
2
|
77
|
1
|
Feb 2006
|
2
|
556
|
3
|
Jan 2006
|
4
|
99.5
|
1
|
Jan 2006
|
1
|
5
|
3
|
Jan 2006
|
4
|
3.14159
|
It would be relational, but I don't know how to convert it to a sorted
and grid-like "view", without a (perl) script. Any thoughts on this?
One thought is to swap the rows and columns. But then I have dates as
the column names, which seems inelegant.