开发者

Need mysql query to add values for each day in a time series... Need help

开发者 https://www.devze.com 2022-12-22 11:58 出处:网络
I have a transaction table and I\'m looking to generate a dataset to drive a li开发者_如何学Cne chart that shows the sum of all the sales happened on each day during a given period.I have never groupe

I have a transaction table and I'm looking to generate a dataset to drive a li开发者_如何学Cne chart that shows the sum of all the sales happened on each day during a given period. I have never grouped results like that before and am scratching my head.

Let's say the table is called "transactions", the "datetime" field is called timestamp, and the sales amount on each transaction is "txn_amount". I want the result set to include each day: "1/2/10" and the sum of the transaction amounts.

I need to get a book and spend a week learning mysql... Thanks for helping me out.


select sum(txn_amount) ,timestamp from transactions where timestamp in (select distinct timestamp from transactions) group by timestamp

if datatype is datetime,Use this

select sum(amt) ,substring(dt,1,10) from transactions where substring(dt,1,10) in (select distinct substring(dt,1,10) from transactions) group by substring(dt,1,10)
0

精彩评论

暂无评论...
验证码 换一张
取 消