pizda

0

Please login or register to vote for this query.

(click on this box to dismiss)

Robotics Meta

Q&A about the site for professional robotic engineers, hobbyists, researchers and students

CREATE TABLE #your_table(item VARCHAR(10), location VARCHAR(10), quantity INT);

INSERT INTO #your_table VALUES ('uk_1', 'a', 100);

INSERT INTO #your_table VALUES ('uk_1', 'a', 11);

INSERT INTO #your_table VALUES ('uk_1', 'c', 10);

INSERT INTO #your_table VALUES ('uk_1', 'c', 7);

INSERT INTO #your_table VALUES ('uk_2', 'a', 3);

INSERT INTO #your_table VALUES ('uk_2', 'a', 1);

INSERT INTO #your_table VALUES ('uk_2', 'a', 2);

INSERT INTO #your_table VALUES ('uk_2', 'c', 10);

INSERT INTO #your_table VALUES ('uk_2', 'c', 11);

SELECT item, 
   SUM(CASE WHEN location = 'a' THEN quantity ELSE 0 END) AS a_sum,
   SUM(CASE WHEN location = 'c' THEN quantity ELSE 0 END) AS c_sum
FROM #your_table
GROUP BY item

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results