从SQL查询中选择唯一的联系人号码
我正在使用如下查询.我不想重复contactno记录.仅应显示具有一个电话号码的用户..我正在使用如下查询,但它给出了类似的错误.您试图执行一个查询,该查询不包含指定表达式"cust_name"作为聚合函数的一部分.
新的OleDbCommand(通过contactno从table1组中选择contactno,cust_name,性别,年龄,地址,职业,国籍",等等);
i am using query like below. I dont want to repeat contactno records. Only user with one phoneno should be shown.. i am using query like below but it is giving error like You tried to execute a query that does not include the specified expression ''cust_name'' as part of an aggregate function.
new OleDbCommand("Select contactno,cust_name,gender,age,address,profession,nationality from table1 group by contactno", con);
如果所选字段为:联系人编号,客户名称,性别,年龄,地址,职业,国籍,可以找到多个记录,则应选择DISTINCT记录.
If the selected fields: contactno, cust_name, gender, age, address, profession, nationality, can be found is multiple records, then you should select DISTINCT records.
Select distinct contactno,cust_name,gender,age,address,profession,nationality from table1
如果要汇总字段(例如:最小值,最大值,计数等),请使用group by子句.
希望有帮助,
蒂姆(Tim)
A group by clause is used if you want an aggregate of a field, ie: min, max, count, etc.
Hope that helps,
Tim
朋友,
我确定您的记录中可能有相同的contactno,但是相应的contactno的其他信息也会有所不同,必须存在数据冗余,并且要解决这种情况,您必须将各个contactno的特定列的不匹配记录进行串联. /> 我认为此链接对您进行查询 http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string [
Hi Friend,
I am sure in your record there could be same contactno but there would also difference in other information of respective contactno there must be a data redundancy and to over come to this situation you have to concatenate unmatched records of particular column of respective contactno.
i think this link would be helpfull to you to make a query http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string[^].
您实际上并没有过滤到查找只有一个电话号码的记录.您可以做的是添加一个having
子句,如下所示:
You aren''t actually filtering to find records with only one phone number. What you could do is add a having
clause like this:
Select contactno,cust_name,gender,age,address,profession,nationality from table1
group by contactno,cust_name,gender,age,address,profession,nationality
having count(contactno) = 1