Distinc关键字不起作用 [英] Distinc Keyword Does not works

查看:123
本文介绍了Distinc关键字不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友..,



我需要删除数据库表中的所有重复值我在distinct关键字的帮助下完成了以下问题但它没有工作请帮助......



<前lang =c#> da = SqlDataAdapter(< span class =code-string> 从数据集中选择DISTINCT日期,湿度,温度,光,电压,输出,cn.con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;







谢谢你......,

有一个Grt日: - )

解决方案

试试这个:





 da =  new  SqlDataAdapter( 从数据集中选择DISTINCT日期,湿度,温度,光,电压,输出,cn.con); 
dt = new DataTable();
da.Fill(dt);

DataView dv = dt( / * default * / true )。DefaultView;



这将删除Datatable dt中的重复条目。


distinct表示唯一所有行必须相同才能区分,例如



如果您有值

日期湿度温度灯电压输出

1 aa 25 36 1 1

2 aa 25 36 1 1



所以如果选择日期,湿度,温度,光线,电压,输出然后它将返回两行



如果选择湿度,温度,光线,电压,输出它将返回一行


它将无法工作因为它会返回至少有记录的行。您需要计算一行的重复次数,然后删除多次的行,您可以使用Identity列来执行此操作。





SELECT id,COUNT(*)TotalCount

FROM items

GROUP BY id

HAVING COUNT(*)> 1

按COUNT排序(*)DESC


Hi friends ..,

I need to remove all the duplicate values from an database table i done the following problem with the help of distinct keyword but it not works pls help...

da = new SqlDataAdapter("select DISTINCT Date,Humidity,Temprature,light,Voltage,outp from Dataset", cn.con);
           dt = new DataTable();
         da.Fill(dt);
           dataGridView1.DataSource = dt;




Thanks You...,
Have a Grt Day :-)

解决方案

Try this:


da = new SqlDataAdapter("select DISTINCT Date,Humidity,Temprature,light,Voltage,outp from Dataset", cn.con);
dt = new DataTable();
         da.Fill(dt);

  DataView dv= dt(/*default*/true).DefaultView;


This will remove duplicate entries from your Datatable dt.


distinct means unique all the rows must be same for distinct for example

if you have values
Date Humidity Temprature light Voltage outp
1 aa 25 36 1 1
2 aa 25 36 1 1

so if you select Date,Humidity,Temprature,light,Voltage,outp then it will return two rows

if you select Humidity,Temprature,light,Voltage,outp it will return one row


It will not work becouse it will return you the rows with atleast having a record. You need to count no of repeatation for a row then delete the rows that are more than once, You can use Identity column to do this.


SELECT id, COUNT(*) TotalCount
FROM items
GROUP BY id
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC


这篇关于Distinc关键字不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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