What is there? There is a table of this type
+----+--------------+-------+--------------+ | id | product_name | count | warehouse_id | +----+--------------+-------+--------------+ | 1 | Puperproduct | 10 | 1 | | 2 | Puperproduct | 15 | 2 | | 3 | Puperproduct | 12 | 3 | +----+--------------+-------+--------------+
What you need to get? You need to get the max and min amount of goods from their warehouses.
+-----+---------------+-----------+------------------+-----------+------------------+ | id | product_name | min_count | min_warehouse_id | max_count | max_warehouse_id | +-----+---------------+-----------+------------------+-----------+------------------+ | 1 | Puperproduct | 10 | 1 | 15 | 2 | +-----+---------------+-----------+------------------+-----------+------------------+
What did I do? Happened:
select id , product_name , min(count) as min_count , max(count) as max_count from table group by product_name +----+--------------+-----------+-----------+ | id | product_name | min_count | max_count | +----+--------------+-----------+-----------+ | 1 | Puperproduct | 10 | 15 | +----+--------------+-----------+-----------+
How do i get warehouses? The number of entries is about 800K. Mysql 5.5
MIN(warehouse_id) as min_warehouse_id, MAX(warehouse_id) as max_warehouse_id
do you need it? - Alexey Shimanskycount == max_count
- zRrr