在 SQLite 中查询
“IN”查询不起作用。如果我错了,请指导我。
KaizenResultsInformationTable 是具有字段“recordinfo”的 MasterTable,该字段包含子表 ID 作为字符串。 kaizenResultsRecordInformationTable 是具有字段“recordId”的子表。
我必须匹配孩子的记录。
查询:
select recordinfo from KaizenResultsInformationTable
输出:;0;1;2;3;4;5;6;7;8;9;10
查询
select substr(replace(recordinfo,';','","'),3,length(recordinfo))
from KaizenResultsInformationTable`
:输出:"0","1","2","3","4", “5”
此查询无效:
select * from kaizenResultsRecordInformationTable
where substr(recordid,0,2) in (
select substr(replace(recordinfo,';','","'),3,length(recordinfo))
from KaizenResultsInformationTable
)
此查询有效:
select * from kaizenResultsRecordInformationTable
where substr(recordid,0,2) in ("0","1","2","3","4","5")
"IN" query is not working. Please guide me if i am wrong.
KaizenResultsInformationTable is MasterTable having field "recordinfo", this field contains Child table Ids as string.
kaizenResultsRecordInformationTable is Childtable having field "recordId".
I have to match records of child.
Query:
select recordinfo from KaizenResultsInformationTable
Output: ;0;1;2;3;4;5;6;7;8;9;10
Query:
select substr(replace(recordinfo,';','","'),3,length(recordinfo))
from KaizenResultsInformationTable`
Output: "0","1","2","3","4","5"
This query is not working:
select * from kaizenResultsRecordInformationTable
where substr(recordid,0,2) in (
select substr(replace(recordinfo,';','","'),3,length(recordinfo))
from KaizenResultsInformationTable
)
This query is working:
select * from kaizenResultsRecordInformationTable
where substr(recordid,0,2) in ("0","1","2","3","4","5")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能像这样使用
in
。在第二个查询中,您将传入
一个包含逗号分隔值列表的字符串。最好将 ID 列表表示为每个值的一条记录。
另外,我不确定你为什么要获取 recordid 的子字符串。您通常应该为每一列存储一个值。
但是,如果您无法更改架构,则可以使用“like”而不是“in”进行字符串匹配。像这样的东西应该可以工作:
因此,如果您的
recordinfo
看起来像1;2;3;4;5;6
,并且您的substr(recordid,0,2 )
看起来像1
,这将包括该行,如果";1;2;3;4;5;6;"就像“%;1;%”
,这是真的。You can't use
in
like that. In your second query, you are passingin
a single string containing a comma-separated list of values.It is better to represent a list of IDs as one record for each value.
Also, I'm not sure why you are taking a substring of your recordid. You should usually be storing one value per column.
However, if you can't change the schema, you can use string matching with 'like' instead of 'in'. Something like this should work:
So if your
recordinfo
looks like1;2;3;4;5;6
, and yoursubstr(recordid,0,2)
looks like1
, this will include that row if";1;2;3;4;5;6;" LIKE "%;1;%"
, which is true.