我有一个 mongo 集合,我想从中获取一些特定数据。我需要每种类型的最新文档。数据如下:
{"id":"100", "type":"A", "date":"2018-01-15T22:19:07.017", "firstName":"Jack", "lastName":"Miller", "age":34}
{"id":"101", "type":"B", "date":"2017-12-04T23:28:49.889", "firstName":"Bob", "lastName":"Jackson", "age":43}
{"id":"102", "type":"B", "date":"2017-12-11T22:06:33.150", "firstName":"Karen", "lastName":"Decker", "age":12}
{"id":"103", "type":"A", "date":"2017-12-18T21:27:31.847", "firstName":"Sally", "lastName":"Rich", "age":19}
{"id":"104", "type":"A", "date":"2017-12-19T23:07:01.292", "firstName":"Joe", "lastName":"Hunk", "age":11}
{"id":"105", "type":"C", "date":"2018-01-08T21:25:25.715", "firstName":"Tallia", "lastName":"Hope", "age":86}
Run Code Online (Sandbox Code Playgroud)
因此,每种类型中最新的将如下所示:
{"id":"100", "type":"A", "date":"2018-01-15T22:19:07.017", "firstName":"Jack", "lastName":"Miller", "age":34}
{"id":"102", "type":"B", "date":"2017-12-11T22:06:33.150", "firstName":"Karen", "lastName":"Decker", "age":12}
{"id":"105", "type":"C", "date":"2018-01-08T21:25:25.715", "firstName":"Tallia", "lastName":"Hope", "age":86}
Run Code Online (Sandbox Code Playgroud)
我认为这里找到的聚合操作(https://docs.mongodb.com/manual/aggregation/)是可行的方法。我尝试使用 $group 累加器对类型进行分组,然后获取 $max 日期,但不知道如何获取文档的其余部分。我可以轻松地通过多个查询来完成此操作,但如果可能的话,我想使用一个查询。
聚合操作是正确的选择吗?也许我在这里缺少一些简单的东西。
我有一张水晶报告的发票,我想调整它,但似乎无法搞清楚.
我的纸底部有一个贴纸(放在盒子上等).我有一个标签,它是报告中的报告页脚,始终打印在页面底部,以便贴在贴纸上.在发票的背面,我打印退货政策和其他信息,以便我们可以节省纸张.发票上有物品和价格清单,通常没有问题.然而,每隔一段时间就会有很多物品迫使标签进入下一页(贴纸的背面).
--------------------------------------------------------------------
| |
| |
| |
| |
| Item 1 Price |
| Item 2 Price |
| Item 3 Price |
| Item 4 Price |
| Item 5 Price |
| Item 6 Price |
| etc. |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|-------------------------------------------------------------------|
| …Run Code Online (Sandbox Code Playgroud) 我有一个允许多个值的参数.它用于我的数据库中的名称字段.我希望能够做的是允许用户输入一个名称,然后让水晶找到任何名称,就像他们输入的任何名字一样.因此,例如,您可以输入4个姓氏,而水晶将返回名称字段中具有任何这些名称的任何人.我可以让"喜欢"工作得很好,但只有当数组中有一个字符串时.这是我的选择公式:
numbervar counter := 1;
numbervar positionCount:=count({?Customer Name}); //I'm not sure what to put
here. Count? UBound?
if {?Customer Name}[1] <> 'ALL'
then
(
while(counter <= positionCount)
do
(
{NAMEFIELD} like '*' & {?Customer Name}[counter] & '*';
counter := counter + 1;
);
)
else
if {?Customer Name}[1] = 'ALL'
then
true
)
Run Code Online (Sandbox Code Playgroud)
此公式返回所有名称,而不是参数中的名称.关于我做错了什么的任何想法?
我有一份报告,其中我试图将一个组的摘要汇总到另一个组.例如:
group 1: 75 <- sum of the maximums
group 2: 50 <- max of the group
line 1: 50
line 2: 40
line 3: 10
group 2: 25 <- max of the group
line 1: 10
line 2: 2
line 3: 25
Run Code Online (Sandbox Code Playgroud)
我尝试过使用总计,但似乎无法做到这一点.我也尝试将最大部分放入公式,但Crystal仍然不会总结它.