我有以下几个目标,并试图为2015年特定行业的总资金提供资金。
{
"_id" : ObjectId("563549877befdba00db4abb2"),
"acquired_year" : 2015,
"industry" : "Games",
"company_info" : {
"company_name" : "Pinion.gg",
"price" : ""
}
}
我将此代码编写成按行业分组,以查找特定行业所花费的收购总金额。
db.acquisitions.aggregate([
{ $match: {"acquired_year":{$gte:2015} } },
{ $project : {"industry":"$company_market", acquired_year:1, "company_info": {"company_name":"$company_name", "price":"$acquistion_price"}}},
{ $group: {"_id":"$industry", "industry_funding":{$sum:"$company_info.price"}}}
])
输出是......
{
"_id" : "Semiconductors",
"industry_funding" : 18861500000
},
{
"_id" : "Coworking",
"industry_funding" : 0
},
{
"_id" : "Stock Exchanges",
"industry_funding" : 365000000
},
我试图找出如何列出每个行业收购价最高的前五大公司。有人有什么建议吗?