有这样一个资料表﹕
a int
b int a         b
0         1    
0         1 
0 2
0 2
0        3
0        3
0        3 
要修改成﹕
a          b
1  1
0          1
1          2
0           2
1           3
0           3
0           3
(如果有多個相同的B的值﹐就只修改其中一具A為1)
我只要修改a 请问这个SQL语句怎幺写

解决方案 »

  1.   

    写程序试试(没有测试)
     
      thevalueofb=Edit1.text;
      with TADOQuery.creat(self) do
        begin
          connection:=Adoconnection1;
          //or connectionstring:='...';
          sql.text:='update table set a='''+'1'+''''+' where a in (select top 1 a from table where  b='''+Edit1.text+''''+')';
          execsql;
        end;
      

  2.   

    上面的代码不对,抱歉
      thevaluesofb=Edit1.text;
      with TADOQuery.create(nil) do
        begin
          connection:=Adoconnection1;
          //or connectionstring:='...';
          sql.text:='select top 1 * from table where b='''+thevaluesofb
                           +'''';
          open;
          Edit;    
          Fieldbyname('a').asstring:='1';
          post;
        end;