数据表中有三个字段如下
A   B    C
01  01   01
01  02   02
01  03   03
01  04   04
02  05   01
02  07   02
02  08   03
02  09   04
02  10   05
03  11   01
03  12   02
已知A、B两个字段,如何通过sql语句得到C字段的值?
数据表的特点是B字段时连续的,而C字段根据A字段保持连续

解决方案 »

  1.   

    select c from table where a='' and b='' 
    难道我理解错了 。不会这么简单吧
      

  2.   

    不需要判断aselect c from table where b='' 
      

  3.   

    --建立测试环境
    Create Table 表(A varchar(10),B varchar(10),C varchar(10))
    --插入数据
    insert into 表
    select '01','01','01' union
    select '01','02','02' union
    select '01','03','03' union
    select '01','04','04' union
    select '02','05','01' union
    select '02','07','02' union
    select '02','08','03' union
    select '02','09','04' union
    select '02','10','05' union
    select '03','11','01' union
    select '03','12','02'--测试语句select a,b,c=(select count(1)+1 from 表 where b<a.b and a=a.a) from 表 a
     
    --删除测试环境
    Drop Table 表/*--
    a          b          c           
    ---------- ---------- ----------- 
    01         01         1
    01         02         2
    01         03         3
    01         04         4
    02         05         1
    02         07         2
    02         08         3
    02         09         4
    02         10         5
    03         11         1
    03         12         2
    *--/
      

  4.   

    我的意思是C字段原来是空的,要通过a、b字段得到,那个是结果