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:
SELECT name, sum(length) AS Length, ST_Union(geometry) geom FROM Trails GROUP BY name;
SELECT
name,
sum(length) AS Length,
ST_Union(geometry) AS geom
FROM
Trails
GROUP BY
name;