Hi @SChalakov ,
I reused your DDL and made some updates on your sample data as below:
DROP TABLE if exists vEventParameter
DROP TABLE if exists vEvent
CREATE TABLE vEventParameter(
EventOriginID VARCHAR(114) NOT NULL
,ParameterIndex VARCHAR(30)
,ParameterValue VARCHAR(30)
);
INSERT INTO vEventParameter(EventOriginID,ParameterIndex,ParameterValue) VALUES
('ID1','1','Value1')
,('ID1','2','Value2')
,('ID1','3','Value3')
,('ID2','1','Value1')
,('ID2','2','Value2')
,('ID2','3','Value3');
CREATE TABLE vEvent(
EventOriginID VARCHAR(114) NOT NULL
,[DateTime] VARCHAR(30)
,EventDisplayNumber VARCHAR(30)
);
INSERT INTO vEvent(EventOriginID, [DateTime],EventDisplayNumber)
values('ID1','2021-02-01 00:00:00','2889')
,('ID2','2021-02-02 00:00:00','2889')
,('ID3','2021-02-03 00:00:00','2889')
select ev.EventOriginId, DateTime,
MAX(CASE WHEN ParameterIndex=1 THEN ParameterValue END) ParamtereValue1,
MAX(CASE WHEN ParameterIndex=2 THEN ParameterValue END) ParamtereValue3,
MAX(CASE WHEN ParameterIndex=3 THEN ParameterValue END) ParamtereValue3
FROM vEvent ev inner join vEventParameter evp
on ev.EventOriginId = evp.EventOriginId WHERE EventDisplayNumber = '2889'
GROUP BY ev.EventOriginId,ev.DateTime
Output:
EventOriginId DateTime ParamtereValue1 ParamtereValue3 ParamtereValue3
ID1 2021-02-01 00:00:00 Value1 Value2 Value3
ID2 2021-02-02 00:00:00 Value1 Value2 Value3
Above result could be correct as you described. If it was unexpected, please provide your sample data and expected output so that we would proceed with checking.
Thank you for understanding!
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.