views:

256

answers:

1

http://www.geocities.com/colinpriley/sql/sqlitepg09.htm has a nice technique for creating a tabular report where the column names for the table can be coded in the query but in my case, the columns should be values from the database. Say I have daily sales figures like:

  Transaction  Date     Rep Product Amount
  1            July 1   Bob A12     $10
  2            July 2   Bob B24     $12
  3            July 2   Ted A12     $25
  ...

and I want a weekly summary report that shows how much of each product each rep sold:

        A12   B24
  Bob   $10   $12
  Ted   $25    $0

My column names come from the Product column. Say, any product that has a row in the specified date range should have a column in the report. But other products -- which weren't sold in that time frame -- should not have a column of all 0s. How can I do that? Bonus points if it works in SQLite.

TIA.

A: 

http://weblogs.asp.net/wallen/archive/2005/02/18/376150.aspx has a good way to extract columns

CodeToGlory
I see how that works but I don't see how it helps. I have rather the opposite problem: I want to create column names (for the crosstab) from data, not data from column names. Maybe my query processor is a little slow today.
Chris Nelson
pivot? http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/
CodeToGlory