I need to convert SQL Server rows into columns along with it value and dates.
Here is my sample dataset:
I required it to be shown like this:
I tried case when conditions and I got this results. But I don't want to make more duplicates.
Code:
SELECT
id,
CASE WHEN name = 'BP' THEN value ELSE NULL AS END AS BP_value,
CASE WHEN name = 'BP' THEN date ELSE NULL AS END AS BP_date,
CASE WHEN name = 'Pulse' THEN value ELSE NULL AS END AS Pulse_value,
CASE WHEN name = 'Pulse' THEN date ELSE NULL AS END AS Pulse_date
FROM
table_name
Result:
Please help me with this.
1条答案
按热度按时间3htmauhk1#
Use aggregation: