I have interesting problem. I've got products that I put into the pallet. Pallet has it own serial number, product ID and quantity number. I'm using PostgreSQL for my database.
For this I use two tables
I use this code to retrieve data that I need:
SELECT products.id_pallets, pallets.id_produkt, CAST(count(*) AS integer) AS real_quantity, pallets.quantity FROM products JOIN pallets ON pallets.id_pallets = products.id_pallets GROUP BY products.id_pallets, pallets.id_produkt, pallets.quantity HAVING count(*) < pallets.quantity
The result of above query looks like this:
id_pallet, id_product, real_quantity, quantity
What I want to do is to add product_timestamp of last product that was inserted into the pallet to the result.
How do I do that since all data that I retrive must appear in GROUP BY sentence, but I want to add to this result not the GROUP OF data but only one data (scalar)?