Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group sales by day of the week

Tags:

sql

mysql

I have a table which looks something like this

sell_price double        buy_price double      time int(11)
31.5                     20.5                  1353755931 (2012-11-27)
20                       10.5                  1353755235 (2012-11-27)
40                       30                    1353752531 (2012-11-26)
50                       25                    1353751237 (2012-11-26)
40                       10                    1353745609 (2012-11-25)           

And I am trying to group all values to get the sales for each day of the week, the desired table should look like the following:

sell_price double        buy_price double      time int(11)
51.5                     30.5                  1353755931 (2012-11-27)
90                       55                    1353755931 (2012-11-26)
40                       10                    1353755931 (2012-11-25) 

I tried the following query but I seem to have a problem with grouping

SELECT sell_price, buy_price, time 
FROM sales 
GROUP BY DAY(time) 
ORDER BY time DESC

The above query returns only 1 row

31.5       20.5      1353755931 

What is the correct way to achieve this?

like image 759
mk_89 Avatar asked Dec 10 '25 01:12

mk_89


1 Answers

SELECT DATE(FROM_UNIXTIME(time)) time,
       SUM(sell_price),
       SUM(buy_price)
FROM tableName
GROUP BY DATE(FROM_UNIXTIME(time))
like image 187
John Woo Avatar answered Dec 12 '25 17:12

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!