<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Generate pairwise combinations in HANA SQL in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647542#M2014780</link>
    <description>&lt;P&gt;Currently, I have a list of records that looks a bit like this (it is actually much longer)&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2148830-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;I would like to generate all pairwise combinations of Field_B with the same value in Field_A. &lt;BR /&gt;If there is only one vleue in Field_B assigned to Field_A, no combination can be generated. Also, a combination of 2 identical vlaues in Field C and Field D in 1 record should not be generated.&lt;BR /&gt;The combinations would be stored in Field_C and Field D&lt;/P&gt;
  &lt;P&gt;The result would look like this&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2151470-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;How can I create this result using HANA SQL?&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 15:32:08 GMT</pubDate>
    <dc:creator>martin_chambers</dc:creator>
    <dc:date>2023-03-14T15:32:08Z</dc:date>
    <item>
      <title>Generate pairwise combinations in HANA SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647542#M2014780</link>
      <description>&lt;P&gt;Currently, I have a list of records that looks a bit like this (it is actually much longer)&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2148830-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;I would like to generate all pairwise combinations of Field_B with the same value in Field_A. &lt;BR /&gt;If there is only one vleue in Field_B assigned to Field_A, no combination can be generated. Also, a combination of 2 identical vlaues in Field C and Field D in 1 record should not be generated.&lt;BR /&gt;The combinations would be stored in Field_C and Field D&lt;/P&gt;
  &lt;P&gt;The result would look like this&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2151470-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;How can I create this result using HANA SQL?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:32:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647542#M2014780</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2023-03-14T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Generate pairwise combinations in HANA SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647543#M2014781</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;martin.chambers&lt;/SPAN&gt;&lt;BR /&gt;The following query can be used to generate the desired result in SAP HANA:&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT&lt;BR /&gt;  Field_A,&lt;BR /&gt;  Field_B,&lt;BR /&gt;  CASE&lt;BR /&gt;    WHEN Field_A = Lag(Field_A) OVER (ORDER BY Field_A) THEN Lag(Field_B) OVER (ORDER BY Field_A)&lt;BR /&gt;    ELSE NULL&lt;BR /&gt;  END AS Field_C,&lt;BR /&gt;  Field_B AS Field_D&lt;BR /&gt;FROM mytable&lt;BR /&gt;ORDER BY Field_A;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;If this response answers your query, please accept it and close the thread.&lt;BR /&gt;Have a wonderful day!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:20:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647543#M2014781</guid>
      <dc:creator>Yogananda</dc:creator>
      <dc:date>2023-03-14T18:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Generate pairwise combinations in HANA SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647544#M2014782</link>
      <description>&lt;P&gt;Hi Muthaiah,&lt;/P&gt;&lt;P&gt;thank you very much for your quick response. I tried your SQL query with my data. &lt;BR /&gt;&lt;BR /&gt;The SQL query results for Field A = 2 are not what I had hoped for. I has been expecting.&lt;BR /&gt;a) The fields C and D are swapped. This is not important.&lt;BR /&gt;b) a "C" in Field C in the 2nd row.&lt;BR /&gt;c) Another 3 records like the ones with Field A = 2 except that the values for Field C and Field D are swapped.&lt;/P&gt;&lt;P&gt;Do you have an idea how to change this?&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;Martin&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2151473-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 15:09:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647544#M2014782</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2023-03-15T15:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Generate pairwise combinations in HANA SQL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647545#M2014783</link>
      <description>&lt;P&gt;I have found a solution.&lt;/P&gt;&lt;P&gt;I just create a self join using only Field A in the on condition. This will create a cartesian product of all records with the same value in Field A. In other words, I have created the paired combinations.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 11:49:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/generate-pairwise-combinations-in-hana-sql/m-p/12647545#M2014783</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2023-03-26T11:49:34Z</dc:date>
    </item>
  </channel>
</rss>

