I have some rows in a database which represent line items in a sale. Each line item has five columns:
- id : Primary key.
- sale_id : The sale that this line-item is a part of (a foreign key to a
Salestable). - product_id : The product this item corresponds to (a foreign key to a
Productstable). - group : The line-items group that this item is a part of.
- is_subitem : Whether this line item is a subitem or not. There is guaranteed to be exactly one "false" value here for any group of line items that have the same
groupvalue.
I would like to iterate over all the rows for a particular sale_id to produce a list where:
- line items with identical
groupvalues are associated together - the line item with
is_subitem == falsefor that group appears first
How can I create a data structure which facilitates this and iterate the way I'd like?