开发者

MySQL: how to create a record that can be queried for matching patterns

开发者 https://www.devze.com 2023-03-26 21:07 出处:网络
I have a phonebook database like this: company开发者_开发问答_name |company_number|company_priority

I have a phonebook database like this:

         company开发者_开发问答_name |  company_number  |   company_priority

Everytime a call comes in, a module in the Asterisk system runs a query against the number to detect what the priority is.

select company_priority from clients where company_number like '%NUMBER%';

And depending on the priority it routes the calls to different routes.

What I am trying to do right now is if there are any special characters that can be put in a record (yes, instead of in the query). like 1800**

Or, can we execute two different queries?Like "select * from xx || select * from xx";

I can't change the variables or the query, since it is built in to the module. My only other option would be to rip open the module and make some changes there.


You can, it works! I'm also surprised! Example:

create table tmp ( a varchar(20) );

insert into tmp values ('%ahoj%'), ('nazdar%');

select * from tmp where 'nazdar   ahoj' like a;

+---------+
| a       |
+---------+
| %ahoj%  |
| nazdar% |
+---------+

So in your case you can fill e.g. 1080% in the company_number column to identify all numbers beginning with 1080. And then test particular NUMBER with this query:

select company_priority from clients where 'NUMBER' like company_number;
0

精彩评论

暂无评论...
验证码 换一张
取 消