How to apply query to select of another query, PostgreSQL 9.6 I have a query, which is working well:

    WITH geom_1 AS 
    (
      SELECT ST_Transform(ST_SetSRID(ST_MakePoint(VAL_1, VAL_2), 4326),32652) 
    ), point_3d AS 
       (
         SELECT  ST_MakePoint(ST_X(st_transform),ST_Y(st_transform), VAL_3) FROM geom_1
        ), static_points AS 
           (
             SELECT geom FROM eco.static_points WHERE name='Korea'
           )   
   SELECT ST_3DDistance(st_makepoint, geom) FROM point_3d, static_points;


It's just needed to provide VAL_1,VAL_2,VAL_3.
I want take them from another query:

WITH param AS (
    SELECT longitude, latitude, altitude
    FROM eco.tracks
    WHERE latitude IS NOT NULL AND longitude IS NOT NULL AND altitude IS NOT NULL
    )


So, input is 3 column, and output is column with distance.
How can I do it?

UPD: Looks like I did

   WITH
    coordinates AS (
    SELECT id, longitude as lon, latitude as lat, altitude as alt FROM eco.tracks WHERE latitude IS NOT NULL AND longitude IS NOT NULL AND altitude IS NOT NULL
    ),
    point_3d AS (
    SELECT  ST_MakePoint(ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)),ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)), alt)  FROM coordinates
    ),
    static_points AS (
    SELECT geom FROM eco.static_points WHERE name='Korea'
    ),
    distance_table AS(
    SELECT  id, ST_3DDistance(ST_MakePoint(ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)),ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)), alt), geom) as distance FROM coordinates, static_points
    )


And updating third one

UPDATE eco.tracks tr
SET distance_1 = dt.distance
FROM distance_table as dt
WHERE tr.id = dt.id
I'm sorry, maybe I'm misreading something but I think you can get it using a single UPDATE.

UPDATE eco_track
SET    distance_1 = ST_3DDistance(ST_MakePoint(ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(longitude, latitude), 4326),32652)),
                                               ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(longitude, latitude), 4326),32652)), altitude), 
                                               (SELECT geom FROM eco.static_points WHERE name='Korea'))
WHERE latitude IS NOT NULL
AND   longitude IS NOT NULL
AND   altitude IS NOT NULL;


point_3d isn't used anywhere

point_3d AS (
    SELECT  ST_MakePoint(ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)),ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(lon, lat), 4326),32652)), alt)  FROM coordinates
    ),


static_points is constant, you can replace it in the UPDATE sentence

SELECT geom FROM eco.static_points WHERE name='Korea'


All the information is on the eco_track table