suppose I have the following table:
+---------+------+-------------+-----+-------+--------+
| invoice | item | description | qty | price | amount |
+---------+------+-------------+-----+-------+--------+
| 1234 | L | labour | 1 | 50 | 50 |
| 1234 | P | parts | 2 | 100 | 200 |
| 9865 | L | labour | 1 | 25 | 25 |
| 9865 | P | parts | 1 | 25 | 25 |
| 5555 | P | parts | 2 | 100 | 200 |
+---------+------+-------------+-----+-------+--------+
I would like a select query that will transpose the 2 rows to columns for each unique invoice number such that each invoice number has only one row.
so for the above example I would expect the following:
+---------+-------+--------------+------+--------+---------+-------+--------------+------+--------+---------+
| invoice | item1 | description1 | qty1 | price1 | amount1 | item2 | description2 | qty2 | price2 | amount2 |
+---------+-------+--------------+------+--------+---------+-------+--------------+------+--------+---------+
| 1234 | L | labour | 1 | 50 | 50 | P | parts | 2 | 100 | 200 |
| 9865 | L | labour | 1 | 25 | 25 | P | parts | 1 | 25 | 25 |
| 5555 | P | parts | 2 | 100 | 200 | NULL | NULL | NULL | NULL | NULL |
+---------+-------+--------------+------+--------+---------+-------+--------------+------+--------+---------+
Note I'm looking for a static/predefined number of columns, not dynamic based on line items.