2014-11-24 17 views
0

当sqlite在语法上按列名。sqlite在语法上,按列

一张表。

_id seq(text) name(text) 
1  2   jone 
2  3   nike 
3  4   sara 

b表。

_id seqs(text) 
1 1,2,3,4 << comma text 

这里是sql。

select group_concat(name) from a where seq in (select seqs from b where _id = '1') 

select group_concat(name) from a as t1 left join 
(select seqs from b where _id = '1') t2 on t1.seq in (t2.seqs) 

我期望下面的结果。 (!!!我想RESULT !!!)

result 
jone,nike,sara 

但是,

query result 
(blank) 

为什么不结果我想要什么?

我能做些什么来获得你想要的结果?

ex) jone,nike,sara 

回答

1

无法搜索使用in逗号分隔字符串(当然,如果你使用动态SQL)。您可以使用like做到这一点:

select group_concat(name) 
from a 
where exists (select 1 from b where b._id = 1 and ',' || b.seqs || ',' like '%,' || a.seq || ',%') 

但是,你不应该在字符串中存储的东西名单。 SQL具有存储列表的这一伟大数据结构 - 事实上,整个语言都是围绕它构建的。它被称为表格。您应该使用每个值具有一行的联结表,而不是将整数值填充到字符串中。