For an invoicing app I'm working on my PHB has decided that the parts sold listed on the invoice need to go in a very unique order. I would like to accomplish this with a single sql statement if possible.
Essentially the order needs to be as such
- The most expensive part (but only if there is another part listed at $0)
- All parts listed at $0
- All other parts (or all parts) listed by order of part_id
- All parts with a part_id of ("MISC-30","MISC-31","TEMP")
- All parts with a negative qty [returns]
There is also a jumble of comments that will need to be added but That will have to be handled by the code
So far I have:
SELECT *
FROM order_part
WHERE ordid = 1234
ORDER BY qty > 0, part_id NOT IN("MISC-30","MISC-31","TEMP"), part_id
However I cannot figure out how to incorporate the first 2 rules