简体   繁体   English

连接两列中的值,并将其与sqlite中的一个值进行比较

[英]concatenate values from two columns and compare it against one value in sqlite

I am using sqlite in one my ios project where among other columns there are two columns. 我在我的ios项目中使用sqlite,在其他列中有两列。 one has country code for mobile dialing like +880 and other column has rest of the mobile number like 1912353697. Now i want to join values from these two columns and compare the result value against like +8801912353697 and if matches pull the corresponding name value in that table . 一个具有用于移动拨号的国家/地区代码,例如+880,另一列具有其余的移动电话号码,例如1912353697。现在,我想将这两列中的值连接起来,并将结果值与+8801912353697进行比较,如果匹配,则将相应的名称值拉入那张桌子。 what would be the right query. 什么是正确的查询。 I have tried like SELECT name FROM CONTACT_LIST WHERE (SELECT mblDc || mbl FROM CONTACT_LIST) = "+8801617634317" ; 我试过像SELECT name FROM CONTACT_LIST WHERE (SELECT mblDc || mbl FROM CONTACT_LIST) = "+8801617634317" ; but that does not work . 但这不起作用。

A help would be appreciated. 一个帮助将不胜感激。

Try: 尝试:

SELECT name FROM CONTACT_LIST 
WHERE mblDc || mbl = "+8801617634317";

From SQLite documentation : The || operator is "concatenate" - it joins together the two strings of its operands. 来自SQLite文档The || operator is "concatenate" - it joins together the two strings of its operands. The || operator is "concatenate" - it joins together the two strings of its operands.

please check How to concatenate strings with padding in sqlite 请检查如何在sqlite中使用填充连接字符串

using substr function we can do the job and the query should be like 使用substr函数,我们可以完成工作,查询应该像

SELECT name FROM CONTACT_LIST WHERE  (mblDc || mbl) = "+8801617634317" ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM