[英]Multiple Select Statement in MYSQL Query
I have aa mysql table contaning date wise sale of products on different marketplaces . 我有一个mysql表,明确在不同的市场上销售产品。
Date Marketplace Sale
1 flipkart 1000
1 flipkart 500
1 amazon 200
1 amazon 1500
1 amazon 700
2 myntra 500
2 flipkart 1000
I want a single mysql statement that gives me date wise gross sale of different marketplaces (amazon,flipkart etc) for a month like in this case on 我想要一个单独的mysql声明,它给我一个月的明确销售不同的市场(亚马逊,flipkart等)一个月,就像在这种情况下
1st of month flipkart gross sale is 1500 (1000+500) , amazon gross sale 2400 (1500+700+200) 1月份flipkart毛销量为1500(1000 + 500),亚马逊毛销售2400(1500 + 700 + 200)
I have this query : 我有这个问题:
SELECT date, (Select sum(gross_sale) from sku where marketplace='flipkart') as flipkart, (Select sum(gross_sale) from sku where marketplace='Myntra') as myntra, sum(gross_sale) as countdate FROM sku WHERE date >= '2017-11-01' AND
date <= '2017-11-30' GROUP BY date ORDER BY date ASC limit 30 ;
but the select subquery doesn't give me date wise distribution , instead the total gross sale of month . 但是,选择子查询并没有给出日期明确的分布,而是给出了月份的总销售额。 how to solve that problem .
如何解决这个问题。 Please help.
请帮忙。 thanks in advance.
提前致谢。
Mysql give you sum()
and group by function for the task. Mysql为您提供
sum()
和group by功能。 You can retrieve the required result by following query 您可以通过以下查询检索所需的结果
select Date, Marketplace, sum(Sale) from table group by Date, Marketplace
sum()
will be sum all the prices of same marketplace with the help of group by
sum()
将在group by
的帮助下将同一市场的所有价格相加
After your comment 你的评论后
If you don't want to use loop and you need single result with query, then you just need where
clause 如果您不想使用循环,并且您需要查询单个结果,那么您只需要
where
子句
select Date, Marketplace, sum(Sale) from table where Marketplace = 'flipkart'
Try this 试试这个
SELECT
sk.date,
sum(sk1.sale) as flipkart_sum_sale,
sum(sk2.sale) as amanzon_sum_sale
FROM
sku sk
LEFT JOIN
sku sk1 ON sk.id = sk1.id
AND sk1.marketplace = 'flipkart'
LEFT JOIN
sku sk2 ON sk.id = sk2.id
AND sk2.marketplace = 'amazon'
GROUP BY sk.date;
select Date,Marketplace, sum(Sale) from table group by Marketplace;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.