如何使用视图在 drupal 中获取 Min() 或 Max() ?
我正在使用 Drupal 的 Views 2,并且需要从自定义表中的字段中检索最小值。如果我用手写的话,这个查询很容易——比如“SELECT foo, min(bar) FROM table GROUP BY foo”。但我该如何使用视图来做到这一点呢?我已经在views.info 文件中定义了该表,因此让视图查看该表没有任何问题。这是我不明白的查询的 Min() 部分。
我的下一站将是 Views API 文档,但如果有人能够提供如何快速完成此操作的大纲,我将不胜感激。
I'm using Drupal's Views 2, and need to retrieve min values from fields in a custom table. The query for this is easy if I were writing it by hand--something like, "SELECT foo, min(bar) FROM table GROUP BY foo." But how would I do this using Views? I've already defined the table in a views.info file, so there's no trouble getting views to see the table. It's the Min() part of the query I just don't understand.
My next stop will be the Views API documentation, but if someone can just provide the outline for how to do this quickly, I would greatly appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
老问题的新答案,但这样的东西会起作用。您需要创建一个自定义字段处理程序,然后按如下方式包装该字段:
New answer to an old question, but something like this will work. You need to create a custom field handler and then wrap the field as follows:
是的,您可以为字段选择最大值、最小值或任何其他选择器。
测试您的结果,但它应该运行良好
降序,然后选择一个要在视图上显示的选项。可以是
显示多个字段时出现问题。
经过第一个测试后,至少在小规模上似乎更快。
yes you can select max, min or any other selector to fields.
Test your results but it should work well
descending and then just pick one to be shown on the view. Can be
problematic when displaying multiple fields or so.
After testing first one seems to be faster at least on small scale.
人们可以考虑模块 groupby 和 views_calc,但我认为它们对您来说是不可接受的。
此外,您可以使用自定义模块来完成此操作。
One could consider the modules groupby and views_calc, but I assume they are not acceptable for you.
Additionally, you can accomplish this with a custom module.