Hi @Dirk Sachse,
Allow me to explain the UPSERT for clarity . If we already have a record with the key in the table , its will update the record else INSERT the record
I already have a the below record in the SQL table
Id , Name
1 , 'Himanshu'
Case 1
if the income record is
1 , 'Dirk'
and Id is the key column
then in the Table you will have an Update and in the record in table will be
1 , 'Dirk'
Case 2
if the incoming record is
2 , 'Sinha'
Then the record will go as INSERT as there is NO record with the ID =2 , so the table will have 2 rows
Id , Name
1 , 'Himanshu'
2 , 'Sinha'
HTH this helps a bit :)
Focus on your query and output , I think you can make in the transformation in the SQL query itself .
create table dbo.Dirk
(
taxonomie_id int
,dm_date int
,ScreenPageViews int
)
INSERT INTO dbo.Dirk values (79540,20230316,1)
INSERT INTO dbo.Dirk values (79540,20230316,1)
INSERT INTO dbo.Dirk values (79540,20230316,1)
INSERT INTO dbo.Dirk values (79560,20230316,1)
INSERT INTO dbo.Dirk values (79560,20230316,1)
INSERT INTO dbo.Dirk values (79560,20230316,2)
INSERT INTO dbo.Dirk values (79530,20230316,1)
INSERT INTO dbo.Dirk values (79530,20230316,3)
WITH table_cte AS (
select taxonomie_id
,dm_date
,ScreenPageViews
,Row_number() OVER(order BY taxonomie_id,dm_date) Row_number
from
dbo.Dirk)
select taxonomie_id,dm_date,ScreenPageViews from table_cte
where ROW_NUMBER in (
select max(Row_number) from table_cte group by taxonomie_id
,dm_date )
order by taxonomie_id,dm_date,ScreenPageViews
Output
taxonomie_id dm_date ScreenPageViews
79530 20230316 3
79540 20230316 1
79560 20230316 2
Let me know if you have any queries .
Thanks
Himanshu