You could do something like this:
Code:
SELECT FRUIT, 'Shop1' AS SHOP, SHOP1 AS QTY
FROM FruitTable
WHERE SHOP1 IS NOT NULL
UNION
SELECT FRUIT, 'Shop2', SHOP2
FROM FruitTable
WHERE SHOP2 IS NOT NULL
UNION
SELECT FRUIT, 'Shop3', SHOP3
FROM FruitTable
WHERE SHOP3 IS NOT NULL
ORDER BY 1, 2
If you wanted to put this data into a new table, you would make the new table first, then you could run this INSERT statement:
Code:
INSERT INTO NewTable (FRUIT, SHOP, QTY)
SELECT FRUIT, 'Shop1' AS SHOP, SHOP1 AS QTY
FROM FruitTable
WHERE SHOP1 IS NOT NULL
UNION
SELECT FRUIT, 'Shop2', SHOP2
FROM FruitTable
WHERE SHOP2 IS NOT NULL
UNION
SELECT FRUIT, 'Shop3', SHOP3
FROM FruitTable
WHERE SHOP3 IS NOT NULL
Note: If your existing "SHOP1/SHOP2/SHOP3" fields have zero instead of NULL, change the WHERE clauses in my example to:
WHERE SHOPx > 0