在线等待,急用,
delphi中的SQL查询
万分感谢!

解决方案 »

  1.   

    打错了,就是查询重复纪录的SQL语句,急用,谢谢
      

  2.   

    重复应该特指某个字段或者是某几个字段的组合上的重复,现做了一个在SQL
    对于字段sales_id上重复的记录的查询,看行吗?
    CREATE TABLE [sales3] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [other_id] [int] NOT NULL ,
    CONSTRAINT [sales_id] UNIQUE  NONCLUSTERED 
    (
    [id]
    )  ON [PRIMARY] 
    ) ON [PRIMARY]
    GOselect * from  sales3 
    where other_id in (select other_id from sales3 group by other_id having count(other_id)>1)
      

  3.   

    Select a.emp_no,a.emp_name,b.emp_no,b.emp_name,a.date_hired
      From employee a
      Join employee b
      On (a.emp_no = b.emp_no and a.date_hired=b.date_hired )
      Orderby a.date_hired
    自己join自己
      

  4.   

    用一ADOConnection与数据库连起来
    再用一ADOQuery与ADOConnection连起来
    再将一DBGrid与ADOQuery连起来(用于显示)!
    ADOQuery.close;
    ADOQuery.sql.clear;
    ADOQueyr.sql.add('select * from  tablename 
    where ID in (select ID from tabname group by ID having count(ID)>1)');
    ADOQuery.open;
      

  5.   

    对,重复就是查某个字段的重复, djkhym(hym)说的很对
    CREATE TABLE [sales3] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [other_id] [int] NOT NULL ,
    CONSTRAINT [sales_id] UNIQUE  NONCLUSTERED 
    (
    [id]
    )  ON [PRIMARY] 
    ) ON [PRIMARY]
    GOselect * from  sales3 
    where other_id in (select other_id from sales3 group by other_id having count(other_id)>1)这样做应该是你想得到的啦。我再给你顶一下,看看还有谬有更好的!!!
      

  6.   

    select field,count(*)
    from table
    group by field
    having count(*) > 0
    field为重复字段,可以是多个
      

  7.   

    select id, glm from rep0001 where cast(glm as varchar) in (select cast(glm as varchar) from rep0001 group by cast(glm as varchar) having count(*)>1) order by id查找GLM字段重复的纪录
      

  8.   

    select 字段1,字段2  from t1
    group by 字段1,字段2 
    having(count(*)>1)
      

  9.   

    其实我认为用count来实现就好多中方法啊,count>1就是重复了,
    不重复的用“DISTINCT”关键字