2017-08-29 56 views
0

多PARAMS实现搜索:
- 域
- GEO
- 引荐
- 其他PARAMS
数据库表看起来像这样:如何通过多个PARAMS从请求中接收

domain | geo | referer | utm | option_id | 
---------|--------|---------|-----|-----------| 
test.com |  |   |  | 1 
test.com | us  |   |  | 2 
test.com | us  | ref.com | 12 | 3 
test2.com| us  |   |  | 4 

例如我收到一些PARAMS请求:

domain=test.com 
geo=us 
referer=ref.com 
utm=12 

如果我做一个查询:

select option_id from table where domain='test.com' and geo='us' and referer='ref.com' and utm='12'; 

它给了我充分的比赛结果只有option_id = 3
但我需要得到所有的选项,每场比赛有域名和地理。
option_id = [1,2,3]

如何以高性能的方式解决问题,也许解决方案不是SQL数据库。我需要实时搜索高负载系统。 帮助将很有用,谢谢。

满足的选择将是该查询:

select option_id from table where domain='test.com' and geo='' and referer='' and utm='' 
UNION 
select option_id from table where domain='test.com' and geo='us' and referer='' and utm='' 
UNION 
select option_id from table where domain='test.com' and geo='us' and referer='ref.com' and utm='12' 

但它是缓慢的,我知道,存在简单的和高性能的解决方案。也许没有SQL数据库

回答

0

如果你想获得的所有匹配,你应该使用则params的至少1个或代替和

select option_id from table where (domain='test.com' OR geo='us' OR referer='ref.com' OR utm='12'); 
+0

我用更多的数据展开我的示例。如果我将使用'或',它会给我选项4的结果为另一个域名 – user1991123

+0

也许我不完全理解你的目标。 你希望所有符合域和地缘的线条,但你说你也想与option_id = 1行,不具有地理 –

+0

认为空值等于任何 – user1991123

0
select option_id from table where domain LIKE '%test.com%' and geo LIKE '%us%' and referer LIKE '%ref.com%' and utm like '%12%'; 

我不是测试代码的选项,但你必须使用像,它会搜索带有模式的组件。

相关问题