-
Notifications
You must be signed in to change notification settings - Fork 117
/
Query.js
130 lines (119 loc) · 2.38 KB
/
Query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 这里是分析数据时用的的查询语句
// 房价均价查询语句
db.lianjia.aggregate([
{
'$match': {
$and: [
{ "address.0": { $exists: true } },
//统计数据的的时间区间,使用的挂牌时间统计
{
"guapaitime": {
$gt: ISODate("2019-07-01T00:00:00.000+0000"),
$lt: ISODate("2019-08-01T00:00:00.000+0000")
}
},
{ "address.0": "成都" }
]
},
},
{
$group: {
_id: { $substr: ["$Link", 0, 22] },
city: { $first: "$address" },
count: { $sum: 1 },
avg_UnitPrice: { $avg: "$UnitPrice" },
std: { $stdDevPop: "$UnitPrice" },
}
},
{
$project:
{
count: 1, //总数
avg_UnitPrice: 1, //每平米均价
std: 1, //标准差
ratio: { $divide: ["$std", "$avg_UnitPrice"] }, //标准差与均价的比值
city: { $slice: ['$city', 0, 1] }
}
},
{
'$sort': { count: -1 }
}
]);
// 平均薪资查询语句
db.zhilian.aggregate([
{'$match': {"workingExp.name": "1-3年"}},
{
$group: {
_id: {"$arrayElemAt": ["$city.items.name", 0]},
count: {$sum: 1},
avg: {$avg: "$avg"},
std: {$stdDevPop: "$avg"},
}
},
{
$project:
{
count: 1, //总数
avg: 1, //平均薪资
std: 1, //标准差
ratio: {$divide: ["$std", "$avg"]} //标准差与均价的比值
}
},
{
'$sort': {count: -1}
}
]);
// 薪资,按公司规模和城市分组
db.zhilian.aggregate([
{
$group: {
_id: {city: {"$arrayElemAt": ["$city.items.name", 0]}, "公司规模": "$company.size.name"},
count: {$sum: 1},
avg: {$avg: "$avg"},
std: {$stdDevPop: "$avg"},
}
},
{
$project:
{
count: 1, //总数
avg: 1, //平均薪资
std: 1, //标准差
ratio: {$divide: ["$std", "$avg"]} //标准差与均价的比值
}
},
{
'$sort': {count: -1}
}
]);
// 当前进度
db.lianjia.aggregate([
{
'$sort': {detailCrawlTime: -1}
}
], {allowDiskUse: true});
// 租房数据
db.lianjia_zufang.aggregate([
{'$match': {"mianji": {$gt: 0}}},
{
$group: {
_id: "$city",
count: {$sum: 1},
avg: {$avg: "$price"},
std: {$stdDevPop: "$price"},
unitPrice: {$avg: {$divide: ["$price", "$mianji"]}}
}
},
{
$project: {
unitPrice: 1, // 单位价格
count: 1, //总数
avg: 1, //每平米均价
std: 1, //标准差
ratio: {$divide: ["$std", "$avg"]} //标准差与均价的比值
}
},
{
'$sort': {count: -1}
}
]);