SQL - add column value to one value

I have a Like This table

Id|purchase_date | Purchase_price
1 |02-May-17     |$10.00
2 |02-May-17     |$20.00
3 |02-May-17     |$30.00

      

I want to write a query where the sum of all buy_price will be calculated based on buy_date. Can anyone please suggest a request?

+3


source to share


3 answers


You can try this with the groupby suggestion

select sum(replace(Purchase_price, '$', '')) as total from tbl group by purchase_date

      



enter image description here

+1


source


Use Mysql function Replace

to remove $

from price, then user SUM

followed by function group by

like

SELECT SUM(REPLACE(Purchase_price,'$','')) AS price from tablename group by purchase_date

      



http://www.w3resource.com/mysql/string-functions/mysql-replace-function.php

0


source


Let's say you go to dynamic currency symbol

SELECT SUM(CAST(SUBSTR(Purchase_price, 2) as DECIMAL(4,2))) FROM tablename GROUP BY purchase_date;

      

0


source







All Articles