# Sql pareto for column values per row help request

**URL:** <https://forum.inductiveautomation.com/t/sql-pareto-for-column-values-per-row-help-request/59119>\
**Category:** Ignition\
**Created:** [May 2, 2022, 2:51pm UTC](https://forum.inductiveautomation.com/t/sql-pareto-for-column-values-per-row-help-request/59119 "2022-05-02T14:51:11Z")\
**Posts on this page:** 1\
**Showing post:** 86

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 14, 2022, 3:06pm UTC](https://forum.inductiveautomation.com/t/sql-pareto-for-column-values-per-row-help-request/59119/86 "2022-09-14T15:06:29Z")

</div>

My requirements changed again.

I have a table like:

```auto
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:

```auto
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 :

> [https://docs.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver16](https://docs.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-ver16)

> [Pivot and Unpivot in SQL - GeeksforGeeks](https://www.geeksforgeeks.org/pivot-and-unpivot-in-sql/)  
> 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.

---

_[View the full topic](https://forum.inductiveautomation.com/t/sql-pareto-for-column-values-per-row-help-request/59119)._
