0

I need to show pivot table or crosstab like this, and my code below the table.

But the result is not the same as shown in the table.

Mach Name 5 4 3 2 1
Spring Assembly Robatech Panel Display control Air Leak Cutter
Spring Assembly Inverter Sensor Conveyor
Spring Assembly No Power
SELECT  machtype AS Machine_Type,
CASE WHEN priors = '5' THEN problems ELSE NULL END AS '5',
CASE WHEN priors = '4' THEN problems ELSE NULL END AS '4',
CASE WHEN priors = '3' THEN problems ELSE NULL END AS '3',
CASE WHEN priors = '2' THEN problems ELSE NULL END AS '2',
CASE WHEN priors = '1' THEN problems ELSE NULL END AS '1'
FROM priority

I try this code but the result is not the same in the table that I shown above.

mest2humb
  • 1
  • 1
  • MACH NAME is the same for all rows in your example so what's the rule for the column entries for each row? is there a category for machine type for example? and why does mach name not appear in your query? – P.Salmon Mar 20 '23 at 06:59
  • I already corrected from Mach Name to Machine_Type. But the expected result is not the same to the sample above – mest2humb Mar 20 '23 at 08:02
  • Please add sample data as text to the question. – P.Salmon Mar 20 '23 at 08:03
  • The value of number '4' is placed on the row 4 & 5 with the same column. Value of number '3' is placed on row 6 & 7 with the same column. Value of number '2' is placed on row 8 with the same column. Value of number '1' is placed on row 9 with the same column. – mest2humb Mar 20 '23 at 08:08

0 Answers0