Skip to content
Advertisement

2 dimensional table query with join and PostgreSQL [closed]

Trying to return a 2 dimensional table from SQL query (Postgres). Read about Pivot Table (but not sure if it is valid for join) and crosstab/tablefunc but no luck.

Expected result

I have 2 tables:

  • applications: name
  • orders: date, …

I’m looking to count orders by month and application.

My attempt so far.

which returns

Thanks.

Advertisement

Answer

To pivot your resultset over a fixed list of values, you can do conditional aggregation:

Note that I modified the where clause so it filters on entire months.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement