我有一個約100,000行的表格。Perl&MySQL - 如何從表中的列中獲得排名前100的最常用字段(包含數字)?
我試圖從列中打印以篩選最常用的「type_num
」。
因此,如果2362在type_num
列中出現1000次,這是最常用的類型,而1234使用了987次等等,我得到一個最常用的頻率爲type_num
的desc列表。
沒有運氣。這是我的新手嘗試:
my $mostused = DBI->connect("$thedb","$user","$password") or die "Connection Error: $DBI::errstr\n";
my $getfreq = $mostused->prepare(qq{SELECT `type_num` count(*) FROM `productstable` GROUP BY `type_num` ORDER BY count(*) DESC LIMIT 10}); ##just tested with 10
$getfreq->execute() or die "Connection Error: $DBI::errstr\n";
while(my ($type_num) = $getfreq->fetchrow_array()) {
print qq~$type_num<br />~;
}
$getfreq->finish(); #not sure if correct
$mostused->disconnect; #not sure if correct
Connection Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'count(*) FROM `productstable` GROUP BY `type_id` ORDER BY count(*) DESC LIMIT 10' at line 1
的type_num的是1至5位數字。 (使用DBI和嚴格的,但這個例子被清理。) 我嘗試了幾個變化和例子,當我在這裏搜索時發現,但是,我做錯了什麼。請幫忙。
你錯過了什麼逗號? – Timmy 2011-05-02 18:05:32
@Timmy:這是一個答案,而不是一個評論:) – ysth 2011-05-02 18:09:02
什麼是'type_num'? – snoofkin 2011-05-02 18:09:10