我有一个transaction表,我希望生成一个数据集来驱动一个折线图,该图表显示给定时间段内每天发生的所有销售的总和。我以前从来没有像这样对结果进行分组,这让我摸不着头脑。
假设该表称为"transactions","datetime“字段称为timestamp,每个事务的销售额为"txn_amount”。我希望结果集包括每天:"1/2/10“和交易金额的总和。
我需要一本书,花一周的时间学习mysql...谢谢你帮我的忙。
发布于 2010-03-05 13:23:22
select sum(txn_amount) ,timestamp from transactions where timestamp in (select distinct timestamp from transactions) group by timestamp如果数据类型为datetime,请使用以下命令
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)https://stackoverflow.com/questions/2384640
复制相似问题