如何计算表格中没有的值? [英] how to count no of values in a table?

查看:77
本文介绍了如何计算表格中没有的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码给出了一个异常,指出"incorrect syntax near the word DISTINCT"
此查询有什么问题?

this code gives a exception saying that "incorrect syntax near the word DISTINCT"
what is wrong in this query?

private SqlConnection con;
private SqlCommand cmd;
private SqlDataReader dr;

openConnection();
string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY DISTINCT V1";
cmd = new SqlCommand(qry1, con);

dr = cmd.ExecuteReader();
while (dr.Read())
{
 count = dr[0].ToString();
}
int ans= Convert.ToInt32(count);
MessageBox.Show(Convert.ToString(ans));

closeConnection();

推荐答案

SELECT COUNT (DISTINCT V1) FROM votes group by v1;


尝试一下...


TRY THIS...


更改此项:

change this:

string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY DISTINCT V1";



与此:



with this:

string qry1 = "SELECT COUNT (V1) FROM votes GROUP BY V1";



希望这会有所帮助:)



hope this helps :)


尝试一下

从投票中选择DISTINCT COUNT(V1),按V1分组
TRY THIS

SELECT DISTINCT COUNT (V1) FROM votes GROUP BY V1


这篇关于如何计算表格中没有的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆