我想从数据库表字中获取前10个数据(按频率)并将字传递给字符串数组。 表名:字 colums:word,frequency
这是我的代码,但我不知道我应该写什么样的循环if if statement;
string[] kyt = new string[10];
SqlCommand com;
string cmr;
con3.Open();
cmr = "SELECT TOP (10) frequency FROM word GROUP BY frequency ORDER BY frequency DESC";
com = new SqlCommand (cmr, con3);
SqlDataReader reader = com.ExecuteReader();
if (reader.Read()) {
}
答案 0 :(得分:1)
使用
SELECT frequency
FROM word
GROUP BY frequency
ORDER BY count(*) DESC
limit 10
然后
List<string> frequencies = new List<string>();
while (reader.Read()) {
string frequency = reader["frequency"].ToString();
frequencies.Add(frequency);
}