MySQL查询问题,有两个表,一个订单表,一个订单明细表,订单表于订单明细表大概结构如下:
--table_orderidpricetime11501483698247212014836874473300148377384743301483788247--tab...
-- table_order
id price time
1 150 1483698247
2 120 1483687447
3 300 1483773847
4 330 1483788247
-- table_orderlist
id total cost order_id
1 1 55 1
2 2 30 1
3 1 60 2
4 1 50 2
5 3 60 3
6 2 50 3
7 1 60 4
8 4 50 4
现在想按日期统计日订单的总价统计和订单成本总计,之前我试了很多种写法都没有成功,希望大神能够指点一下;最后统计出的结果应该是如下
sum(price) sum(total*cost) data
270 225 2017-01-06
630 540 2017-01-07 展开
id price time
1 150 1483698247
2 120 1483687447
3 300 1483773847
4 330 1483788247
-- table_orderlist
id total cost order_id
1 1 55 1
2 2 30 1
3 1 60 2
4 1 50 2
5 3 60 3
6 2 50 3
7 1 60 4
8 4 50 4
现在想按日期统计日订单的总价统计和订单成本总计,之前我试了很多种写法都没有成功,希望大神能够指点一下;最后统计出的结果应该是如下
sum(price) sum(total*cost) data
270 225 2017-01-06
630 540 2017-01-07 展开
1个回答
展开全部
SELECT
sum(price),
sum(total * cost),
DATE_FORMAT(
FROM_UNIXTIME(time, '%Y-%m-%d') AS DATA
FROM
table_order t1,
table_orderlist t2
WHERE
t1.id = t2.order_id
GROUP BY
DATE_FORMAT(
FROM_UNIXTIME(time, '%Y-%m-%d')
sum(price),
sum(total * cost),
DATE_FORMAT(
FROM_UNIXTIME(time, '%Y-%m-%d') AS DATA
FROM
table_order t1,
table_orderlist t2
WHERE
t1.id = t2.order_id
GROUP BY
DATE_FORMAT(
FROM_UNIXTIME(time, '%Y-%m-%d')
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询