How to add the aliases to the group by clause In the below query how to add the aliases assignedTOiti, assignedTOasstAdm, assignedTOhlp, closedDate to the group by clause.

I am struggling for the past few hours.

SELECT ieor.aper07_req_k                                  AS reqno,
       ford.apeh09_supervisor_cds_d                       AS ll6CdsID,
       'Ford Offboard Req'                                AS reqtype,
       par_val1.aper17_parameter_val_x                    AS requeststatus,
       (SELECT Min(iti2.aper07_req_created_s)
        FROM   iaper07_employee_offbrd_req iti2
        WHERE  ieor.aper07_req_k = iti2.aper07_req_k
               AND iti2.aper06_req_status_k = 4)          AS assignedTOiti,
       (SELECT Min(hlp2.aper07_req_created_s)
        FROM   iaper07_employee_offbrd_req hlp2
        WHERE  ieor.aper07_req_k = hlp2.aper07_req_k
               AND hlp2.aper06_req_status_k = 5)          AS assignedTOasstAdm,
       (SELECT Min(asst2.aper07_req_created_s)
        FROM   iaper07_employee_offbrd_req asst2
        WHERE  ieor.aper07_req_k = asst2.aper07_req_k
               AND asst2.aper06_req_status_k = 12)        AS assignedTOhlp,
       (SELECT Min(clsd2.aper07_req_created_s)
        FROM   iaper07_employee_offbrd_req clsd2
        WHERE  ieor.aper07_req_k = clsd2.aper07_req_k
               AND clsd2.aper06_req_status_k IN ( 3, 9 )) AS closedDate,
       ieor.aper07_assigned_to_cds_d,
       ieor.aper07_comment_x,
       ieor.aper07_last_updt_user_c,
       ieor.aper07_last_updt_s                            AS last,
       ieor.apeh09_employee_k,
       ieor.aper06_req_status_k,
       ipw.apeh04_first_n,
       ipw.apeh04_cds_d,
       ipw.apeh04_last_n,
       ipw.apeh04_person_type_c,
       irs.aper06_req_status_x,
       offr.aper15_offboard_reason_x                      AS offboardReason,
       Min(aper07_req_created_s)                          AS creationDate
FROM   iaper07_employee_offbrd_req ieor,
       iapeh05_person_vw ipw,
       iapeh09_ford_employee ford,
       iaper06_req_status irs,
       iaper15_offbrd_req_reason offr,
       iaper17_parameter_values par_val1
WHERE  ford.apeh09_cds_d = ipw.apeh04_cds_d
       AND ieor.apeh09_employee_k = ipw.apeh04_visitor_k
       AND irs.aper06_req_status_k = ieor.aper06_req_status_k
       AND offr.aper15_offboard_reason_k = ieor.aper15_offboard_reason_k
       AND ieor.aper06_req_status_k = par_val1.aper17_parameter_val_r
       AND ipw.apeh22_region_k = 1
       AND ieor.aper07_last_updt_s = (SELECT Max(aper07_last_updt_s)
                                      FROM   iaper07_employee_offbrd_req b
                                      WHERE  ieor.aper07_req_k = b.aper07_req_k)
       AND ieor.aper07_req_k = 3387
GROUP  BY ieor.aper07_req_k,
          ford.apeh09_supervisor_cds_d,
          ieor.aper07_assigned_to_cds_d,
          ieor.aper07_comment_x,
          ieor.aper07_last_updt_user_c,
          ieor.aper07_last_updt_s,
          ieor.apeh09_employee_k,
          ieor.aper06_req_status_k,
          ipw.apeh04_first_n,
          ipw.apeh04_cds_d,
          ipw.apeh04_last_n,
          ipw.apeh04_person_type_c,
          irs.aper06_req_status_x,
          par_val1.aper17_parameter_val_x,
          offr.aper15_offboard_reason_x
HAVING ipw.apeh04_person_type_c NOT IN( 'c', 'C' )
Using the with clause will help keep your queries readable:

with &lt;some_meaningful_name&gt; as (
  select
    &lt;complex_expression1&gt; as &lt;alias1&gt;,
    &lt;complex_expression2&gt; as &lt;alias2&gt;,
    &lt;other_columns&gt;
  from
    ...
)
select
  &lt;some_columns&gt;,
  &lt;aggregate_expression&gt;
from
  some_meaningful_name
group by
  &lt;some_columns&gt;;