ASP对ACCESS查询问题,刚才有个帖子,但要求我没想清楚。

三仙半 2006-05-11 09:19:37
我有两个表:会员表(userInfo)和店长表(regie)。
userInfo三个字段:userID(代码),wage(工资),isRegie(是否为店长)
regie两个字段:userID(代码),subsidy(津贴)
两个表用userID连接。如果userInfo中的isRegie为true,则regie必然有一条记录与该userID对应
查询要求:1、每条记录选取userID、wage、subsidy三个字段
2、userInfo中wage不为0的,全要;
3、userInfo中wage为0的,如果isRegie为true而且subsidy不为0的,也要。
例子:
userInfo中的数据如下:
A 100 true
B 0 true
C 100 true
D 0 true
E 100 false
F 0 false
regie中的数据如下:
A 0
B 50
C 50
D 0
选择结果应该是
A 100 0
B 0 50
C 50 50
E 100 (这里可以是空值)
...全文
197 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Scarroot 2006-05-12
  • 打赏
  • 举报
回复
偶也献丑一下:
select userid,wage,subsidy
from userinfo a
left join regie b
on a.userid = b.userid
where (a.wage <> 0 and a.wage not is null)
or (a.wage = 0 and a.isregie = true and b.subsidy <> 0 and b.subsidy not is null)
tujunask 2006-05-12
  • 打赏
  • 举报
回复
response.write rs1("userid")&"</br>"
改成:

response.write "["&rs1("userid")&"]"
response.write "["&rs1("wage")&"]"
response.write "["&rs1("subsidy")&"]</br>"


字段 isregie 我用的是文本格式
tujunask 2006-05-12
  • 打赏
  • 举报
回复
试验成功的笨办法:由于我对SQL的表的链接搞不好,所以我用的极笨的办法,先用循环把两个表连接成一个表:(上面水平高的一行程序就解决)即
新表:newtable:
A 100 true 0
B 0 true 50
C 100 true 50
D 0 true 0
E 100 false 0
F 0 false 0
<%
set conn=server.createobject("ADODB.CONNECTION")
conn.open "DBQ="+server.mappath("A.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
set rs1=server.createobject("adodb.recordset")
sql1="select * from newtable where (isregie='"&"true"&"' and subsidy>0 "&") or wage>0"
rs1.open sql1,conn,1,1
'response.write rs1.recordcount
for i=1 to rs1.recordcount
response.write rs1("userid")&"</br>"
rs1.movenext
next
rs1.close
conn.close
%>


运行结果显示:
[A][100][0]
[B][0][50]
[C][100][50] 你的C行50 50 不对吧
[E][100][0]

三仙半 2006-05-12
  • 打赏
  • 举报
回复
starsword(星剑传奇)的方法在我这里实验通过了,结果是我预想的。
得到大家的支持,通过对大家提供的方法的实验我学到了很多东西,谢谢大家!
感觉分给少了,我又追加了30分,以后有问题还希望大家帮忙。
starsword 2006-05-12
  • 打赏
  • 举报
回复
select userInfo.userID,userInfo.wage,regie.subsidy from userInfo left outer join regie on userInfo.userID = regie.userID where (userInfo.wage<>0) or (userInfo.wage=0 and userInfo.isRegie='true' and regie.subsidy<>0)

我没试,但这样应该可以
underone 2006-05-12
  • 打赏
  • 举报
回复
Select a.userID,a.wage,b.subsidy From userInfo as a,regie as b Where (a.userID = b.userID and a.isRegie = true and b.subsidy <> 0) or (a.userID <> b.userID and a.wage <> 0)
创造奇迹9999 2006-05-12
  • 打赏
  • 举报
回复
Select a.userID,a.wage,b.subsidy From userInfo as a,regie as b Where (a.userID = b.userID and a.isRegie = true and b.subsidy <> 0) or (a.userID <> b.userID and a.wage <> 0)

这样试下
创造奇迹9999 2006-05-12
  • 打赏
  • 举报
回复
Select a.userID,a.wage,b.subsidy From userInfo as a,regie as b Where (a.userID = b.userID and a.isRegie = true and b.subsidy <> 0) or a.wage <> 0

这次一定可以了,上面还有一个小条看没看到
三仙半 2006-05-12
  • 打赏
  • 举报
回复
我试验了二位的办法:
czq9966(宁录):你的办法得到的结果是A、B、C
Scarroot(转战 C Sharp):你的办法得到的结果是A、C、E。
我通过事务规则得到的结果是A、B、C、E;还要请大家再给想想办法。
创造奇迹9999 2006-05-11
  • 打赏
  • 举报
回复
Select a.userID,a.wage,b.subsidy From userInfo as a,regie as b Where a.userID = b.userID and (a.wage <> 0 or a.isRegie = true and b.subsidy <> 0)

看看这样对不,我的SQL不太过关,
三仙半 2006-05-11
  • 打赏
  • 举报
回复
这事有点着急,大家多帮忙啊!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧