Sign-up....

没有多少分了!

如果我要判断表中一个字段为"yes"的在表中占多少比率要怎么实现呀!!!!

请贴出代码!

[46 byte] By [msdn] at [2007-8-14 9:08:52]
# 1 Re: 没有多少分了!

比如我要判断的字段名字为a

rs.movefirst

dim i

dim j

j=0

for i=1 to rs.recordcount

if rs(a)="yes" then

j=j+1

end if

rs.movenext

next

后面select count(a) as b from 表

dim c

c=cdbl(j)/cdbl(rs(b))

response.write c

hbhbhbhbhb1021 at 2005-3-29 17:20:52 >
# 2 Re: 没有多少分了!

上面可行,效率不计的话!

lstup at 2005-3-29 17:24:52 >
# 3 Re: 没有多少分了!

select count(id)/(select count(id) from table) from table where 字段='yes'

用rs(0)得到结果

scoutlin at 2005-3-29 17:30:57 >
# 4 Re: 没有多少分了!

好象要用两句sql的。

select count(*) as cnt from table

select count(*) as cnt1 from table where field='yes'

rs("cnt")/rs1("cnt1")

myvicy at 2005-3-29 17:33:03 >
# 5 Re: 没有多少分了!

一句就够了

scoutlin at 2005-3-29 17:36:34 >

Web

All Classified