2015-10-16 95 views
0

我在我的項目中使用續集,我有問題從數據庫獲取非唯一記錄ID。 我有如下表:該表獲取非唯一記錄與續集

table = Sequel::Model.db[:csv_temp] 

和記錄是這樣的:

table.all 

[{:id=>1, 
    :school_identifier=>"school_id_1", 
    :school_name=>"school_name_1", 
}, 
{:id=>2, 
    :school_identifier=>"school_id_1", 
    :school_name=>"school_name_2", 
}] 

我怎樣才能獲得的記錄的id這school_identifier是不是唯一的?

回答

1

下面是做到這一點的一種方式,有可能是其他人:

DB[:csv_temp]. 
    where(:school_identifier=>DB[:csv_temp]. 
    select_group(:school_identifier). 
    having{count{}.* > 2}). 
    select_map(:id) 
+1

這不工作... –

+0

哎呀。應該可能是'> = 2'。 –