My database layout:
ID Description Shop 1 Shop 2 Shop 3
1 | Article Description | 19.99 | 29.99 | 4.99
2 | Article Description | 45.94 | 14.54 | 87.5
I think its best to do it via PHP on the application layer , but you can do it with LEAST()
and GREATEST()
:
SELECT t.id,t.description,
LEAST(t.shop1,t.shop2,t.shop3) as lowest,
(t.shop1+t.shop2+t.shop3) - (LEAST(t.shop1,t.shop2,t.shop3) + GREATEST(t.shop1,t.shop2,t.shop3)) as middle_one
GREATEST(t.shop1,t.shop2,t.shop3) as biggest
FROM YourTable t