You could use this expression on a Geometry Generator symbol layer of type LineString
:
with_variable('group', "code"||'_'||"line number",casewhen $id = array_min( array_agg( $id, group_by:=@group ) )then make_line( array_agg( expression:=$geometry, group_by:=@group, order_by:=$id ) )end)
Groups are created by concatenating the "code"
, an underscore, and "line number"
fields. This value is assigned to a variable for better maintainability.
The case
statement is to ensure the line is rendered only once per group, rather than once for every point. See this thread for more details.