I have a line layer with hiking trails. The hiking trails are divided into their surfaces. So one hiking trail consist of parts with different surfaces.

I would like to use a virtual layer to group the trails by their name and determine the proportions of the path surfaces (in distance and percentage).

**Example:**
Trail A 20km/100%: 5km/25% Gravel, 10km/50% Asphalt, 5km/25% Path

The very simple SQL-Query for grouping and summing the parts for every trail is:

<!-- language: sql -->

    SELECT
	    name,
	    sum(length) AS Length,
	    ST_Union(geometry) AS geom
    FROM
	    Trails
    GROUP BY
	    name;

[![enter image description here][1]][1]

  [1]: https://i.sstatic.net/CmZ8C.png