我有一个表名tblb,它有一个列日志名称,我存储日志名称。
如何编写sql查询以计算具有相同名称的日记名称并在标签中显示该数字? 例如 在tblb
Journalname
-----
abc
abc
abc
def
def
通过文本框输入和按钮点击例如
textbox.Text = "abc";
label.Text = 3;
textbox.Text = "def";
label.Text = 2;
答案 0 :(得分:0)
从分组后的选择中获得回报
select journalname, count(0) [count] from tblb group by journalname;
答案 1 :(得分:0)
SQL:
SELECT Journalname, COUNT(*) [Count] FROM tblb
GROUP BY Journalname
<强>数据表:强>
var results = (from j in myDataTable.AsEnumerable()
group j by j["Journalname"].ToString() into grp
select new
{
Journalname = grp.key.ToString(),
Count = grp.Count()
}).ToList();
您现在可以遍历结果并更新UI:
foreach(var journal in results)
{
// Update UI - Choose appropriate text box for each journal
textbox.Text = journal.Journalname;
label.Text = journal.Count.ToString();
}
答案 2 :(得分:0)
在SQL Server上有这样的语句:
SELECT Journalname, COUNT(*) AS dupes
FROM tblb
GROUP BY Journalname
//Add this line if you want to display only duplicate values
//HAVING (COUNT(*) > 1)
会返回这样的内容:
Journalname | dupes
abc | 3
def | 2
在您的代码中,您必须遍历SQL结果并将其显示在您的页面上。