1 Reply Latest reply on Jan 16, 2020 6:25 AM by Marwim

    grouping

    4171650

      Can you please help me for the below scenario.  I have data in the table like this.

       

      Employee_IDCOLUMN_ACOLUMN_BCOLUMN_C
      ABC Y
      ABC N
      ABCY
      XYZN
      XYZ N

       

      I am looking for the output data like below.

        

      Employee_IDCOLUMN_ACOLUMN_BCOLUMN_C
      ABCYYN
      XYZN N
        • 1. Re: grouping
          Marwim

          Hello,

           

          this is the forum space for the tool SQL Developer. For questions about SQL SQL & PL/SQL would be a better place.

           

          And you usually get faster answers if you include test data as a script so we can easily test our replies (Re: 2. How do I ask a question on the forums?)

           

          Assuming that there is only one value in each column per employee you can do it like this:

           

          WITH test_data AS (

            SELECT 'ABC' employee_id, NULL column_a, 'Y'  column_b, NULL column_c FROM dual UNION ALL

            SELECT 'ABC' employee_id, NULL column_a, NULL column_b, 'N'  column_c FROM dual UNION ALL

            SELECT 'ABC' employee_id, 'Y'  column_a, NULL column_b, NULL column_c FROM dual UNION ALL

            SELECT 'XYZ' employee_id, 'N'  column_a, NULL column_b, NULL column_c FROM dual UNION ALL

            SELECT 'XYZ' employee_id, NULL column_a, NULL column_b, 'N'  column_c FROM dual

            )

          SELECT employee_id,MAX(column_a),MAX(column_b),MAX(column_c)

          FROM test_data

          GROUP BY employee_id;

           

          Regards

          Marcus