I am trying to construct a query that creates separate columns based on the field_number column below. The query should be grouped by the lead_id. The form_id is the contest (I would need to be able to change the form_id manually based on the contest I need stats for). The field_number each number represents a column I would need to create. So 1 = email, 4 = First Name, 5 = Last name etc. etc.
Any help on how I need to do this is appreciated. There is an example below of the table I need to grab the data from.
+-----+---------+---------+--------------+---------------------------------+
| id | lead_id | form_id | field_number | value |
+-----+---------+---------+--------------+---------------------------------+
| 1 | 1 | 3 | 1 | [email protected] |
| 2 | 1 | 3 | 4 | Michael |
| 3 | 1 | 3 | 5 | Smith |
| 4 | 1 | 3 | 6 | eNewsletter Sign Up Form |
| 5 | 2 | 3 | 1 | [email protected] |
| 6 | 2 | 3 | 4 | Jack |
| 7 | 2 | 3 | 5 | Johnson |
| 8 | 2 | 3 | 6 | eNewsletter Sign Up Form |
| 9 | 3 | 3 | 1 | [email protected] |
| 10 | 3 | 3 | 4 | Bobbie |
| 11 | 3 | 3 | 5 | DeLeon |
| 12 | 3 | 3 | 6 | eNewsletter Sign Up Form |
| 13 | 4 | 3 | 1 | [email protected] |
| 14 | 4 | 3 | 6 | H&H eNewsletter Sign Up Form |
| 15 | 5 | 3 | 1 | [email protected] |
| 16 | 5 | 3 | 4 | Judy |
| 17 | 5 | 3 | 5 | Byers |
| 18 | 5 | 3 | 6 | eNewsletter Sign Up Form |
| 19 | 6 | 3 | 1 | [email protected] |
| 20 | 6 | 3 | 4 | Andre |
| 21 | 6 | 3 | 5 | M |
| 22 | 6 | 3 | 6 | eNewsletter Sign Up Form |
| 23 | 7 | 3 | 1 | [email protected] |
| 24 | 7 | 3 | 4 | Larry |
| 25 | 7 | 3 | 5 | Landerson |
| 26 | 7 | 3 | 6 | eNewsletter Sign Up Form |
| 27 | 8 | 3 | 1 | [email protected] |
| 28 | 8 | 3 | 4 | Stephanie |
| 29 | 8 | 3 | 6 | eNewsletter Sign Up Form |