0

i have in database like this

say a table X with columns A and B

X
--
A B
1 300
1 400
1 100
2 200
2 400

and i want to write sql query to get result in format

P Q
1 800
2 600

Where Q is sum of all having same value of A.

I thought of selecting the data in same format and then using the logic display it is there a way to do with SQL query?

3 Answers 3

4
SELECT A as P, SUM(B) AS Q
FROM X
GROUP BY A
Sign up to request clarification or add additional context in comments.

Comments

4
select  A as P
,       sum(B) as Q
from    X
group by
        A

Comments

1
SELECT A AS P, SUM(B) AS Q
FROM TableA
GROUP BY A

Comments

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.