表table中有三个字段,其中序号字段内容中均未填,其中a1,a2字段有内容(如左图),如要在  
  DBGrid中显示这个表三个字段的内容,并且查询条件:a1字段内容为长春,a2字段内容为0431,并且
  还要求查询出的xuhao字段分别从上至下序号自动加一,(如右图),请问SQL语句应如何写?
  最好帮我试一下!!  xuhao    a1      a2                    xuhao    a1     a2
  
  null     北京    010                   1        长春   0431 
  null     北京    010                   2        长春   0431
  null     北京    010                   3        长春   0431
  null     北京    012
  null     长春    0431
  null     长春    0431
  null     长春    0431
  null     长春    0432

解决方案 »

  1.   

    將序號改為計算字段select a1, a2 from 表名 where a1 = '长春' and a2 = '0431'
      

  2.   

    procedure TForm1.Table1CalcFields(DataSet: TDataSet);
    begin
      DataSet.FieldByName('xuhao').AsInteger := DataSet.RecNo;
    end;
      

  3.   

    上面的BDE的, 沒測試ADO用
    procedure TForm1.Table1CalcFields(DataSet: TDataSet);
    begin
      DataSet.FieldByName('xuhao').AsInteger
      := TADODataSet(DataSet).Recordset.AbsolutePosition;
    end;ADO的測試過
      

  4.   

    请看好所要实现的功能,原xuhao中没有内容,检索之后列出序号,不论检索条件是什么,序号都从1开始,有几条最后的数字是几。
      

  5.   

    select * from table 
                  where a1='长春'
                  a2='0431 order by xuhao
      

  6.   

    Select xuhao=Identity(int,1,2),a1,a2 into #temp from test1 where a1='长春' and a2='0431'select * from #temp
      

  7.   

    Select xuhao=Identity(int,1,1),* into #temp  from tabel1 where field1 = '长春' and field2 = '0431'
    select * from #temp
      

  8.   

    Select xuhao=Identity(int,1,1),* into #temp  from tabel1 where field1 = '长春' and field2 = '0431';
    select * from #temp;
    drop table #temp;