简体   繁体   English

如何从包含数据库行的Ruby变量中查找唯一行

[英]How to find unique rows from a Ruby variable containing database rows

I have these line of code in Ruby: 我在Ruby中有以下代码行:

connection = ActiveRecord::Base.connection()
@mastertest = connection.execute("select code_ver, suite, date from mastertest order by date desc limit 30")

So mastertest contains all the rows from my database table. 因此,mastertest包含数据库表中的所有行。

I want only all rows which have a unique value of code_ver from the results. 我只希望结果中具有唯一值code_ver的所有行。 How do I find that ? 我怎么找到那个?

您可以尝试以下方法:

@mastertest = connection.execute("select distinct code_ver, suite, date from mastertest where code_ver = "#{@variable}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM