标签:style blog color 数据 width re
今天有一位朋友发了这么个场景:一个商店的收入记录表,每天都有记录;
日期 | 每天收入 |
07/11 | 100 |
07/12 | 102 |
07/13 | 103 |
07/14 | 101 |
现在做一个统计,用户希望看到自已的收入统计
日期 | 每天收入 |
07/11 | 100 |
07/12 | 202 |
07/13 | 305 |
07/14 | 406 |
CREATE TABLE IF NOT EXISTS `income` ( `id` int(11) NOT NULL, `idate` date DEFAULT NULL, `money` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `idate` (`idate`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
select a.idate ,sum(b.money) as num from income as a left join income as b on b.idate<=a.idate group by a.idate order by a.idate
SELECT id, idate, (@rowNum := @rowNum + money) AS total FROM income, ( SELECT (@rowNum := ifnull( (SELECT sum( money ) FROM income WHERE id <=0 ) , 0)))b ORDER BY id limit 0,30
标签:style blog color 数据 width re
原文地址:http://www.cnblogs.com/yahoo85/p/3863627.html