if you are using SQL Server, try something likeselect sum (case when score >= 60 and score < 70 then 1 else 0 end) as count from yourtable

解决方案 »

  1.   

    一般说,用count,sum etc. vfp命令因为优化机制的原因效率都要比相应的sql语句效率低,用下列方法试试:
    select 1 from yourtable into cursor tmpcur where field1>=data1 and field1<data2 
    ss=_tally
    ?? ss
      

  2.   

    尊敬的VFP高手:
        对上面我提出的问题我还要进一步说明:当我在用这样一系列语句计算时效率极低:
        count to ss(1) for field1>=90 and field1<100
        count to ss(2) for field1>=80 and field1<90
        count to ...
        ....
        ....
        ....
        
        有没有只用一句高效的语句来代替?
          
      

  3.   

    这是一个生成表的方法
    select sum(case when field1>=90 and field1<100 then 1 else 0 end) as ss1,
       sum(case when field1>=80 and field1<90 then 1 else 0 end) as ss2,
       ...
       from table
      

  4.   

    select sum(iif(field1>=90 and field1<100,1,0)) as ss1,sum(iif(field1>=80 and field1<90,1,0)),... as ss2 from table1
      

  5.   

    select sum(iif(field1>=90 and field1<100,1,0)) as ss1,sum(iif(field1>=80 and field1<90,1,0)) as ss2 from table1
      

  6.   

    select count(*) from tablename
      

  7.   

    应该采用liuri的方法是最好的。
      

  8.   

    我也一直是这么写的。比较喜欢用sql,一句话解决问题。