mysql 按天统计记录
天蓬老师
天蓬老师 2017-04-17 15:14:21
0
4
647

突然想不想来这SQL应该怎么写

现在两字段
time 为时间戳
value 为某一笔交易金额
如何用sql查出所有的天的交易金额统计,得到类似下面的数据,如果某一天没有记录,那就为0,但也查询出来,如下面18号

day amount
2016-07-19 999
2016-07-18 0
2016-07-17 777
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
伊谢尔伦

"How to use SQL to find out the transaction amount statistics of all days"? ? What does it mean? Is it the total daily statistical amount?

左手右手慢动作
SELECT FROM_UNIXTIME(time),'%Y-%m-%d') AS day,SUM(value) AS amount FROM table GROUP BY day;

未测试
巴扎黑

select FROM_UNIXTIME(time, '%Y-%m-%d') AS day, sum(value) AS amount from table group by day

If you want to display the statistical date that does not exist, you need to implement it in the program

PHPzhong

SELECT
YEAR(time ) year,
MONTH (time )month,
DAY(time )day,
SUM(value )amount
FROM
TABLE
WHERE

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!