Home > database >  The SQL query for help column turned (different)
The SQL query for help column turned (different)

Time:10-25

Especially, how to convert the following form?

CodePudding user response:

Please someone teach? Ask for help

CodePudding user response:

Select id, name, jidu, xiaoshou from (select 1 id, 'apple' name, 1000 Q1, Q2 2000, 3300 in Q3, Q4 5000
The FROM DUAL UNION ALL
SELECT id, 2 'orange' name, 3000 Q1 and Q2 3000, 3200 Q3 and Q4 1500
The FROM DUAL UNION ALL
SELECT 3 id, a 'banana' name, 2500 Q1 and Q2 3500, 2200 Q3 and Q4 2500
The FROM DUAL UNION ALL
SELECT 4 id, 'grapes' name, 1500 Q1 and Q2 2500, 1200 Q3 and Q4 3500
The FROM DUAL) unpivot (xiaoshou jidu in (q1, q2, q3 and q4));

CodePudding user response:

Select the date, 'rock1 as rock, rock1 temp as temp, rock1 press as press from table
Union ALL
Select the date, 'rock2 as rock, rock2 temp as temp, rock2 press as press from table
Union ALL
.

CodePudding user response:

Thank you for your advice, I solved the problem of a
  • Related