<?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>Question Re: combining pivot and window in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838335#M4869178</link>
    <description>&lt;P&gt;you have right, and I see the difference in your answer.
But in my question to AI I have told him that I am expecting 2 columns.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2024 05:49:10 GMT</pubDate>
    <dc:creator>Baron</dc:creator>
    <dc:date>2024-04-23T05:49:10Z</dc:date>
    <item>
      <title>combining pivot and window</title>
      <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaq-p/13838331</link>
      <description>&lt;P&gt;I can't solve this "simple" problem, can maybe someone help?&lt;/P&gt;
&lt;P&gt;What I have is:
&lt;/P&gt;&lt;PRE&gt;create or replace table mytable (whichamount int, whichdate date)
insert into mytable values
(100, '2024-01-01'),
(200, '2024-01-01'),
(300, '2024-02-01'),
(400, '2024-03-01'),
(500, '2024-04-01'),
(600, '2024-04-01');
&lt;/PRE&gt;
What I want is:
&lt;PRE&gt;whichdate, whichamount1, whichamount2
'2024-01-01', 100, 200
'2024-02-01', 300, null
'2024-03-01', 400, null
'2024-04-01', 500, 600
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 04:53:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaq-p/13838331</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2024-04-23T04:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: combining pivot and window</title>
      <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838333#M4869176</link>
      <description>&lt;P&gt;This is one solution from AI:
&lt;/P&gt;&lt;PRE&gt;SELECT 
    whichdate,
    MAX(CASE WHEN rn = 1 THEN whichamount END) AS whichamount1,
    MAX(CASE WHEN rn = 2 THEN whichamount END) AS whichamount2
FROM (
    SELECT 
        whichdate,
        whichamount,
        ROW_NUMBER() OVER (PARTITION BY whichdate ORDER BY whichamount) AS rn
    FROM mytable
) t
GROUP BY whichdate
ORDER BY whichdate;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 05:14:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838333#M4869176</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2024-04-23T05:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: combining pivot and window</title>
      <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838334#M4869177</link>
      <description>&lt;P&gt;What does the AI tell when there are more than 2 entries for the same "whichdate"?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 05:17:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838334#M4869177</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2024-04-23T05:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: combining pivot and window</title>
      <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838332#M4869175</link>
      <description>&lt;P&gt;Here's a similar take with PIVOT:&lt;/P&gt;
&lt;PRE&gt;SELECT *
FROM ( SELECT 
        whichdate,
        whichamount,
        ROW_NUMBER() OVER (PARTITION BY whichdate ORDER BY whichamount) AS rn
    FROM mytable
     ) PivotSourceData
   PIVOT ( 
      LIST (whichamount)
      FOR rn IN ( 1 as whichamount1, 2 as whichamount2)
   ) PivotedData
ORDER BY whichdate;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 05:32:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838332#M4869175</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2024-04-23T05:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: combining pivot and window</title>
      <link>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838335#M4869178</link>
      <description>&lt;P&gt;you have right, and I see the difference in your answer.
But in my question to AI I have told him that I am expecting 2 columns.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2024 05:49:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/combining-pivot-and-window/qaa-p/13838335#M4869178</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2024-04-23T05:49:10Z</dc:date>
    </item>
  </channel>
</rss>

