I have the following table logs:
session_id | event_type   | event_value
-----------+--------------+------------
   505     | user_profile | /admin
   505     | page_viewed  | /profile/18
   506     | user_profile | /member
   506     | page_viewed  | /home
   507     | user_profile | /admin
   507     | page_viewed  | /profile/18
   508     | user_profile | /member
   508     | page_viewed  | /profile/18
I would like to group by all possible values in event_type (user_profile and page_viewed), and count each possible combinaison.
The result should look like this:
user_profile | page_viewed | count
-------------+-------------+------
   admin     | /profile/18 |  2    # session_ids 505 and 507
   member    | /home       |  1    # session_ids 506
   member    | /profile/18 |  1    # session_ids 508
Note that the couple user_profile, page_viewed may change. It may be, for example, user_profile, user_gender, session_duration.
Counting/grouping over multiple columns could be done like that, but I have no idea how to select rows dynamically...
Is it possible to do such a query with postgresql ?
 
     
     
    