I took a portion of your data and simplified the numbers to save time, and ran a test.
create table test(Timestamp datetime,
AVERAGE_of_Recv_Percemt_Utilization int,
AVERAGE_of_Xmit_Percemt_Utilization int);
insert into test values
('5/3/2023 1:47:54 AM',82,6),
('5/3/2023 1:48:54 AM',38,7),
('5/3/2023 1:49:54 AM',40,14);
;with T1 as(
select 'AVERAGE_of_Recv_Percemt_Utilization' as a,
case when Timestamp = '5/3/2023 1:47:54 AM'
then AVERAGE_of_Recv_Percemt_Utilization end as b,
case when Timestamp = '5/3/2023 1:48:54 AM'
then AVERAGE_of_Recv_Percemt_Utilization end as c,
case when Timestamp = '5/3/2023 1:49:54 AM'
then AVERAGE_of_Recv_Percemt_Utilization end as d
from test
),T2 as(
select a,max(b) as [5/3/2023 1:47:54 AM],
max(c) as [5/3/2023 1:48:54 AM],
max(d) as [5/3/2023 1:49:54 AM] from T1 group by a
),T3 as(
select 'AVERAGE_of_Xmit_Percemt_Utilization' as e,
case when Timestamp = '5/3/2023 1:47:54 AM'
then AVERAGE_of_Xmit_Percemt_Utilization end as f,
case when Timestamp = '5/3/2023 1:48:54 AM'
then AVERAGE_of_Xmit_Percemt_Utilization end as g,
case when Timestamp = '5/3/2023 1:49:54 AM'
then AVERAGE_of_Xmit_Percemt_Utilization end as h
from test
),T4 as(
select e,max(f) as [5/3/2023 1:47:54 AM],
max(g) as [5/3/2023 1:48:54 AM],
max(h) as [5/3/2023 1:49:54 AM] from T3 group by e)
select * from T2
union all
select * from T4;
Output:
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
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.