社区
ASP
帖子详情
数据查询包含问题求教
mysoho
2004-05-07 02:12:56
比如数据库中有记录:
name parentstr
张三 0,22
李四 0,22
王五 0,23,25
赵六 0,21
孙七 0,22
我只有一个字串“0,22,34,36”作为条件, 如何把所有“0,22”的记录查出来。
...全文
114
11
打赏
收藏
数据查询包含问题求教
比如数据库中有记录: name parentstr 张三 0,22 李四 0,22 王五 0,23,25 赵六 0,21 孙七 0,22 我只有一个字串“0,22,34,36”作为条件, 如何把所有“0,22”的记录查出来。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhuq
2004-05-07
打赏
举报
回复
你可以用模糊查询
Miriamy
2004-05-07
打赏
举报
回复
我就是读了一遍数据库
有符合的就存入findID中
dim PStr,Str,Fin,FindID,Cid
Str="0,22,35,43"
sql="select * form table"
rs.open sql,conn,1,3
for i=1 to rs.recordcount
CiD=rs("ChannelID")
PStr=rs("ParentStr")
Fin=Instr(1,Str,PStr)
if Fin > 0 then
FindID=Cid
FindID1=FindID1&","&FindID
end if
rs.movenext
next
response.write FindID1
Sql="select * from table where ChannelID in ("&FindID1&")"
Miriamy
2004-05-07
打赏
举报
回复
上面的有点错误
自已改一下吧
Miriamy
2004-05-07
打赏
举报
回复
dim PStr,Str,Fin,FindID
Str="0,22,35,43"
sql="select * form table"
rs.open sql,conn,1,3
for i=1 to rs.recordcount
PStr=rs("ParentStr")
Fin=Instr(1,Str,PStr)
if Fin<>0 then
FindID=rs("ChannelID")
FindID=FindID&","&rs("ChannelID")
end if
rs.movenext
next
response.write FindID
Sql="select * from table where ChannelID in ("&FindID&")"
mysoho
2004-05-07
打赏
举报
回复
还有人知道吗?谢谢。
mysoho
2004-05-07
打赏
举报
回复
谢谢 stayhere(且留连) 的答复,
但是作为查询条件的字传是变动的,我不能确定可以split成数组的上标,这个查询条件是动态得到的,可能是0,22,35,43 也可能是0,22,35也可能是0,22。然后我要从数据库中取出所有parentstr包含在该字传中的记录。
mysoho
2004-05-07
打赏
举报
回复
是我没说清楚吗?再说一下,
比如数据库中是这样的:
id ChannelID BoardType ParentID ParentStr
31 4 以太网 0 0
32 4 1394 0 0
33 4 801.11b 0 0
34 4 801.11g 0 0
35 4 ATMEL 22 0,22
36 4 Dallas 22 0,22,32
37 4 INTEL 22 0,22
38 4 LG 22 0,22
39 4 Motorola 22 0,21,24
40 4 Philips 22 0,22
41 4 Winbond 22 0,22
42 4 51系列 35 0,22,35
43 4 AVR系列 35 0,22,35
现在有个记录xxx的parentstr是:0,22,35,43 我想得到数据库中parentstr被包含在xxx的parentstr的所有,如parentstr是:0/0,22/0,22,35/这样的记录符合条件,但0,22,31或0,21,24就不符合条件。
请问我如何写查询语句呢?
stayhere
2004-05-07
打赏
举报
回复
不知道你的意思是把所有包含还等于"0,22"或"0,22,34"
strArr=split("0,22,34,36",",")
等于:
sql="select * from tbl where parentstr='" & strArr(0) & "," & strArr(1) & "'"
sql=sql & " or parentstr='" & strArr(0) & "," & strArr(1) & "," & strArr(2) "'"
包含:
sql="select * from tbl where parentstr liek '%" & strArr(0) & "," & strArr(1) & "%'"
sql=sql & " or parentstr liek '%" & strArr(0) & "," & strArr(1) & "," & strArr(2) "%'"
gu1dai
2004-05-07
打赏
举报
回复
不知道你什么意思
gu1dai
2004-05-07
打赏
举报
回复
wo ye我也不知道
mysoho
2004-05-07
打赏
举报
回复
补充,比如数据库中有记录:
name parentstr
刘二 0,22,34
张三 0,22,24
李四 0,22
王五 0,23,25
赵六 0,21
孙七 0,22
我只有一个字串“0,22,34,36”作为条件, 如何把所有“0,22”或“0,22,34”的记录查出来。也就是如何取出数据库中parentstr字段的内容被包含于查询条件字串的记录。
LeetCode 104. Maximum Depth of Binary Tree和111. Minimum Depth of Binary Tree 递归
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
LeetCode: 111. Minimum Depth of Binary Tree
LeetCode: 111. Minimum Depth of Binary Tree 题目描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest...
[LeetCode 111] Minimum Depth of Binary Tree
题目链接:minimum-depth-of-binary-tree /** * Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest
Leetcode 111 Minimum Depth of Binary Tree(水)
题目连接:Leetcode 111 Minimum Depth of Binary Tree解题思路:递归,每次返回子树中层数低的一个加一。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * ...
LeetCode之111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note:A leaf is a node with no childre...
ASP
28,402
社区成员
356,940
社区内容
发帖
与我相关
我的任务
ASP
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
复制链接
扫一扫
分享
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章