 (
   SELECT
     icustay_id,
-    FIRST_VALUE(valuenum) over W AS weight_first,
-    MIN(valuenum) over W AS weight_min,
-    MAX(valuenum) over W AS weight_max
+    FIRST_VALUE(weight) over W AS weight_first,
+    MIN(weight) over W AS weight_min,
+    MAX(weight) over W AS weight_max
     FROM weightdurations
     WINDOW W AS
     (
       PARTITION BY icustay_id
-      ORDER BY charttime
+      ORDER BY starttime
       ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
     )
 )

(
  SELECT
    icustay_id,
    FIRST_VALUE(valuenum) over W AS height_first,
    MIN(valuenum) over W AS height_min,
    MAX(valuenum) over W AS height_max
    FROM ht_fix
    WINDOW W AS
    (

      WHEN c.itemid IN (920, 1394, 4187, 3486, 226707)
        THEN c.valuenum * 2.54
      ELSE c.valuenum
    END AS height
  FROM chartevents c
  WHERE c.valuenum IS NOT NULL
  AND c.valuenum != 0
