My requirements changed again.
I have a table like:
Machine | Hot_Rejects | Cold_Rejects | Deformed_Rejects
B1 | 5 | 3 | 0
B2 | 0 | 2 | 1
B3 | 2 | 4 | 1
I need it to look like:
Line | Reason_Top_3 | Qty_top_3_Reasons
B1 | Hot_Rejects | 5
B1 | Cold_Rejects | 3
B1 | Deformed_Rejects | 0
B2 | Cold_Rejects | 2
B2 | Deformed_Rejects | 1
B2 | Hot_Rejects | 0
B3 | Cold_Rejects | 4
B3 | Hot_Rejects | 2
B3 | Deformed_Rejects | 1
If I have three reject reasons though, I can't figure out how to pivot multiple columns to the rows.
I looked on :
Pivot and Unpivot in SQL - GeeksforGeeks
I only see how to pivot just one column which has to be an aggregate, and I continually get a an error revolving around a comma or index however I try to put in more columns.
I really want to be able to do this in SQL, but if I have to do it in a script, then I will do that.
I am working on the script now, but if someone could help me with the SQL, I would appreciate it.