Pivot add-on in cross-tab table Postgresql
caveats below

With tablefunc

First you need to add the tablefunc extension

CREATE EXTENSION tablefunc;


What you need is something like this,

SELECT *
FROM crosstab(
  $$
    SELECT 0, coalesce(continent, 'Total'), count(city.name)
    FROM encompasses AS e
    JOIN country ON e.country = country.code
    JOIN city ON country.code = city.country
    GROUP BY GROUPING SETS ((e.continent), ())
    ORDER BY 1, 2;
  $$,
  $$VALUES ('Africa'), ('America'), ('Asia'), ('Australia/Oceania'), ('Europe'), ('Total')$$
) AS t(rowid int, africa int, america int, asia int, australia_oceania int, europe int, total int);


Should get ya done.

Of course none of this works with the sample data because none of those countries have entires in encompasses,

INSERT INTO encompasses (country, continent) VALUES ('GR', 'Africa');

 rowid | africa | america | asia | australia_oceania | europe | total 
-------+--------+---------+------+-------------------+--------+-------
     0 |      4 |         |      |                   |        |     4
(1 row)


You may want to replace 

$$VALUES ('Africa'), ('America'), ('Asia'), ('Australia/Oceania'), ('Europe')$$


with

$$ SELECT DISTINCT continent FROM encompasses ORDER BY 1; $$


But either way, you'll have to type that out in the table definition (the list in the t(rowid int...))

Caveats

I don't actually do this in my code, ever. This pivot is a waste of time and computation. I would always do this in whatever language I'm using to interact with the db. I don't actually think this is a good idea (here). But this is how it's done.