查找最后的订单限制

时间:2011-04-04 12:12:00

标签: ruby-on-rails

<% Specimen.find(:all, :order => 'distribution_sheet_id', :limit => 10).each do |df| %>
  <%= df.id %>
<% end %>

这给出了这个查询:

SELECT * FROM "specimens" ORDER BY distribution_sheet_id LIMIT 10

我需要这个:

SELECT * FROM "specimens" ORDER BY distribution_sheet_id DESC LIMIT 10

我正在使用Rails&lt;请帮忙吗?

3 个答案:

答案 0 :(得分:3)

DESC添加到订单值的末尾。

Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10)

完整示例:

<% Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %>
  <%= df.id %>
<% end %>

答案 1 :(得分:0)

只需添加DESC

即可
Specimen.find(:all, :order => 'distribution_sheet_id DESC', :limit => 10).each do |df| %> <%= df.id

答案 2 :(得分:0)

Specimen.
  all(:order => 'distribution_sheet_id DESC', :limit => 10, :select => :id).
  map(:&id)