On 12/5/2013 1:15 PM, Hayden Livingston wrote:
I have a table schema such like

ID | Col1 | Col2 | Col3 | Value
1      a        null     null    X
2      null      a       null    Y
3     null       null      a     Z
4      b          null    null   A
5      null      b       null    B
6     null       null      b     C

Right now these are in the same table (they may be different tables in the
near future, but I don't think that impacts this discussion)

I want to "PIVOT" this data such that:

A | Value | Value | Value
a     X         Y          Z
b     A         B          C

select coalesce(Col1, Col2, Col3) as A,
  max(case when Col1 is null then null else Value end) as Value1,
  max(case when Col2 is null then null else Value end) as Value2,
  max(case when Col3 is null then null else Value end) as Value3
from MyTable group by A;

I must say you chose a very inconvenient table schema. What's with the sparse matrix? What kind of queries is this good for?
--
Igor Tandetnik

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

Reply via email to