1

I have a table trade as follows:-

bm  | m   | price | amount | total    | status
USD | BTC | 0.01  | 1      | 0.01     | active
USD | BTC | 0.01  | 2.5    | 0.025    | active
USD | BTC | 0.4   | 0.5    | 0.020    | active 
USD | BTC | 0.4   | 0.22   | 0.088    | active

I want to add amounts of duplicate price i.e 0.01 and 0.4 as well as total together in one output where status is active and show them so that the result is like:-

price | amount  | total
0.01  | 3.5     | 0.035
0.4   | 0.722   | 0.108

4 Answers 4

2

You could group according to the price and sum the other columns:

SELECT   price, SUM(amount), SUM(total)
FROM     trade
WHERE    status = 'active'
GROUP BY price
Sign up to request clarification or add additional context in comments.

3 Comments

Is there a way to remove the comma , from the result?
@JeffB what comma?
Let's say result is 7,000 ... but i want result to be only 7000 without comma ,
1

you could use aggregation function sum() and group by price

select   , price , sum(amount) , sum(total) 
from my_table  
group by   price  

1 Comment

Is there a way to remove the comma , from the result?
1

try this with group by:

select price, sum(amount) as amount,sum(total) as total
from tablename where status='active'
group by price

2 Comments

Is there a way to remove the comma , from the result?
Lets say result is 7,000.00 ...I want only 7000 without comma
1

you can try something like this:

SELECT *, sum(amount) AS totalAmount,sum(total) AS total 
FROM TABLE_NAME 
GROUP BY price;

3 Comments

Is there a way to remove the comma , from the result?
You can't use * for this query in any flavour of SQL I know. You are returning bm and m which are not aggregated. You could either specify price instead of * or group by bm, m, price
Lets say result is 7,000.00 ...I want only 7000 without comma

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.