0

I want to get sum quantity of A and B in new column named group1 and group 2 have distinct value with Category . And want to get both columns in same execution .

c1   |   c2
---------------
A    |   2
B    |   1
A    |   2
B    |   1
A    |   2
B    |   1




result :


group1 | group2
---------------
A      | 6
B      | 3

I am trying this query but not working

 SELECT SUM(c2) WHERE DISTINCT c1 in('A','B') as 'group2' from table,
    SELECT DISTINCT c1 in('A','B') as 'group1' from table

1 Answer 1

2

Just a straightforward group by. Based on your example:

SELECT c1 as group1, SUM(c2) as group2 
FROM table
GROUP BY c1
Sign up to request clarification or add additional context in comments.

2 Comments

not working , I have tried with table reference also . Can you please put the query in complete syntax ?
Are you getting an error? In my example, replace "table" with the name of the table, like FROM mytable, where "mytable" is the name of your table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.