具有反向LIKE条件的查询

时间:2017-08-30 13:53:26

标签: sql sqlite android-sqlite

有一个列名为" phone"并且具有不同格式的不同数字。

示例:

id | number
1  | 03439879098
2  | 01109890032
3  | +91 932 3233237

现在,如果我想搜索" 3233237"然后查询将是:

select * from table where number like '%3233237%';

结果将是:

id | number
3  | +91 932 3233237

但在我的情况下,我想反向

String search = "+92 343 9879098"

select * from table where number like search

结果应为:

id | number
1  | 03439879098

因为列数字和搜索字符串有一个共同的字符串, 9879098

查询的设计应使其查找搜索字符串和列值都具有公共子字符串的记录

请给我一些想法。

2 个答案:

答案 0 :(得分:1)

This was a tricky one. You can do it in pure SQL executing:

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080
  # nginx
  config.vm.network "forwarded_port", guest: 80, host: 6600
  # # development site
  config.vm.network "forwarded_port", guest: 3000, host: 6660
  # db browser port
  config.vm.network "forwarded_port", guest: 7474, host: 6666
  # test port
  config.vm.network "forwarded_port", guest: 8800, host: 6606

Here we're concatenating the number column with the wildcards %.

*Also You could resolve it programatically:

dropdownMenu.dataSource = self;
dropdownMenu.delegate = self;

Cheers.

答案 1 :(得分:-1)

您是否尝试过NOT LIKE,因此它会像

一样

select * from table where name not like search