Current Table data
------------------

Table name: Application App

```
id  | applied_class  |  applied_date
----+-------+-------------------------------
 27 | city1          | 2013-03-11 23:47:04.167624-04
 28 | city1          | 2013-03-11 23:58:28.90088-04
 29 | city2          | 2013-03-12 00:39:05.955988-04
 30 | city3          | 2013-03-12 01:07:28.30229-04
 31 | city2          | 2013-03-12 09:46:32.778106-04
 32 | city1          | 2013-03-12 23:06:52.262773-04
 33 | city2          | 2013-03-14 14:28:40.401831-04
 34 | city3          | 2013-03-15 19:33:59.346832-04
 35 | city2          | 2013-03-16 05:51:11.354835-04

```

Desired Output.
---------------

It is an aggregate count of records over time, grouped by date (day) and city.

```
date        |  city1   |  city2   |  city3 
------------+----------+----------+--------
2013-03-11  |   2      |   0      |    0        
2013-03-12  |   3      |   2      |    1
2013-03-13  |   3      |   2      |    1
2013-03-14  |   3      |   3      |    0    
2013-03-15  |   3      |   3      |    2
2013-03-16  |   3      |   3      |    0

```

Current (Failing) Query
-----------------------

I'm trying to progress through the query step by step, and I've hit a wall. The query below returns the following error (note that these queries are all working when I run them by themselves, outside of crosstab):

> 
> DETAIL: SQL rowid datatype does not match return rowid datatype.
> 
> 
> 

```
select *

from crosstab(
    $$select temp_table.d,  
       applied_class,  
       sum(temp_table.ct) over (order by d) 

    from   
       (
        select count(id) ct, 
               applied_class, 
               date_trunc('day', applied_date) d from application_app 
        where applied_class like '%L13' 
        group by applied_class, d 
        order by d
        ) as temp_table

    order by 1, 2$$)  -- end crosstab

as ct ("day" date, "city1" text, "city2" text, "city3" text);

```