Home > database >  Write view content into a field name
Write view content into a field name

Time:09-27

The original table


Now to create a view to the inside of the "temperature" "humidity" strain "into" the view of the field name, followed by the monitoring value, could you tell me how to operate?

CodePudding user response:

Not very understand what's specific needs,

CodePudding user response:

Under the line column, the pivot to understand

CodePudding user response:

The CREATE table vacc (
Vaa1 varchar (200),
Vaa2 varchar (100),
Vaa3 float
)

SELECT * FROM vacc

INSERT INTO vacc VALUES (' humidity ', '20191221', '32.3')
INSERT INTO vacc VALUES (' temperature ', '20191222', '32.3')
INSERT INTO vacc VALUES (' humidity ', '20191223', '33.3')
INSERT INTO vacc VALUES (' temperature ', '20191223', '36.3')
INSERT INTO vacc VALUES (' strain ', '20191225', '155')
INSERT INTO vacc VALUES (' crack ', '20191225', '0.143')

SELECT * FROM vacc
AS P
The PIVOT
(
The SUM (P.v aa3) FOR
Humidity p.v aa1 (IN [], [temperature], [strain], [crack])
) AS T


/* the results
Vaa2 humidity, temperature and strain fracture
20191221 32.3 NULL NULL NULL
20191222 NULL NULL NULL
32.320191223 33.3 36.3 NULL NULL
NULL NULL 155 0.143 20191225
*/
  • Related