asp 遍历数据库 判断结果

来源:百度知道 编辑:UC知道 时间:2024/05/29 18:11:09
这是数据库asass的字段表
id 用户 地区
1 hao123 北京
2 hao123 沈阳
3 hao123 海口
4 admin 拉萨
5 admin 北京
6 admin 西安
判断用户hao123 和 admin 的地区只要有一个(或一个以上)相等就打印“1 ”
如果一个也没有就打印“0”
请根据以上信息写出详细的asp代码,连接数据库文件(conn)可以省略!!

如果单用户不存在地区相同就可以这样:
set rs=conn.execute("select count(*) as xx from 表 where 用户='hao123' or 用户='admin' group by 地区")
if rs("xx")>=1 then
response.write("1")
else
response.write("0")
end if

如果存在相同:
set rs=conn.execute("select * from 表 where 地区 in (select 地区 from 表 where 用户='admin')") and 用户='hao123'")
if not rs.eof then
response.write("1")
else
response.write("0")
end if