我正在使用SQL Server 2016,我无法弄清楚如何构建该查询.
假设我有一个这样的表格:
ID EntryTime ResultTime
1 2016-05-02 13:30:00 2016-05-02 21:50:00
2 2016-05-02 14:45:00 2016-05-02 22:00:00
3 2016-05-02 16:30:00 2016-05-02 22:21:00
4 2016-05-03 01:00:00 2016-05-03 03:33:00
5 2016-05-03 10:30:00 2016-05-04 07:47:00
6 2016-05-03 12:30:00 2016-05-03 22:45:00
7 2016-05-04 11:30:00 2016-05-05 21:30:00
8 2016-05-04 12:30:00 2016-05-04 22:58:00
9 2016-05-04 13:30:00 2016-05-04 23:04:00
10 2016-05-04 13:45:00 2016-05-04 22:59:00
11 2016-05-04 14:00:00 2016-05-04 22:59:00
12 2016-05-04 14:15:00 2016-05-04 23:04:00
13 2016-05-04 17:45:00 2016-05-04 21:47:00
14 2016-05-05 23:30:00 2016-05-06 03:25:00
15 2016-05-05 23:45:00 …
Run Code Online (Sandbox Code Playgroud) 假设我要存储以下文档:
{
"item_id": 1,
"item_price": 500,
"currency": "USD"
}
Run Code Online (Sandbox Code Playgroud)
我希望货币字段像ENUM,所以我可以预定义一组值,例如:“ USD”,“ GBP”,“ EUR”等等。
我还希望每个值都与一个整数相关,例如哈希映射,因此值集将如下所示:
{ "USD":1, "GBP":2, "EUR":3 }
Run Code Online (Sandbox Code Playgroud)
我如何映射此字段?
我正在尝试在Elasticsearch中进行简单的查询,但是我不知道该怎么做。我在整个互联网上进行了搜索,没有关于这种情况的讨论。
假设我有类似的物品:
{
"item_id": 1,
"item_price": 100,
"item_quantity": 2
},
{
"item_id": 2,
"item_price": 200,
"item_quantity": 3
},
{
"item_id": 3,
"item_price": 150,
"item_quantity": 1
},
{
"item_id": 4,
"item_price": 250,
"item_quantity": 5
}
Run Code Online (Sandbox Code Playgroud)
我想进行查询,以得到股票总价的结果。
例如:100 * 2 + 200 * 3 + 150 * 1 + 250 * 5
该查询的结果应该是2,200
最后一个数据的答案查询正在运行,但是这种复杂的情况呢:
POST tests/test2/
{
"item_category": "aaa",
"items":
[
{
"item_id": 1,
"item_price": 100,
"item_quantity": 2
},
{
"item_id": 2,
"item_price": 150,
"item_quantity": 4
}
]
}
POST tests/test2/
{ …
Run Code Online (Sandbox Code Playgroud)