0

我有两列访问和访问序列,

Example table

Visit         Visit_sequence
1             43:65:34:21:343
2             22:78:113:37
3             43:465:72:21:1187:542

The semi colon is present in the field.

现在如果我想检查一个访问是否有包含数字 43、65 和 21 的访问序列。我应该使用什么条件(最短条件)?

如果我写

 case when visit_sequence like '%:43:%:65:%:21:%'

或者

 case when visit_sequence like '%43%:%65%:%21%'

这些肯定行不通。我不需要整个代码,只需要like.

4

2 回答 2

1
select *
  from visits
 where ':'+visit_sequence+':' like '%:43:%'
   and ':'+visit_sequence+':' like '%:65:%'
   and ':'+visit_sequence+':' like '%:21:%'

我希望你有一个小表,因为你的非规范化存储格式不会因为这个问题而抛出任何类型的查询。

于 2012-10-09T07:52:14.593 回答
0

如果您使用 ORACLE, 请尝试REGEXP_LIKE

  select *
  from visits
  where REGEXP_LIKE (visit_sequence, '43:.*65:.*21')
于 2014-02-13T01:54:41.630 回答