当列包含针时,MYSQL查找子字符串

时间:2016-10-06 05:11:27

标签: mysql substring

如果数据库中包含针,我怎样才能在数据库中找到字符串?

例如我有字符串: “www.example.com/test”

我的数据库列urlColumn包含: “www.example.com”

如果我执行以下操作(伪):

SELECT * FROM db WHERE urlColumn LIKE '%www.example.com/test%'

我没有得到结果。如果我将其更改为(伪):

SELECT * FROM db WHERE urlColumn LIKE '%www.example.com%'

有效。 LIKE之后的元素必须是针而不是大海捞针才是真的吗?有可能做这样的事情(伪):

SELECT * FROM db WHERE %urlColumn% LIKE 'www.exmaple.com/test'

1 个答案:

答案 0 :(得分:2)

如果输入字符串可以视为SELECT * FROM db WHERE 'www.example.com/test' LIKE CONCAT('%',urlColumn,'%'); ,那么您可以使用下面给出的查询:

HayStack

更多

还有另一种方法可以动态确定应将哪个字符串视为Needle,哪些字符串应视为SET @hayStack := 'www.example.com'; SET @needle := 'www.example.com/test'; SELECT IF(LENGTH(@hayStack) > LENGTH(@needle), @hayStack LIKE CONCAT('%',@needle,'%'), @needle LIKE CONCAT('%',@hayStack,'%') )

这是一个简单的演示:

name: "Test_net"
layer {
  name: "data"
  type: "HDF5Data"
  top: "Inputdata"
  top: "label"
  hdf5_data_param {
    source:"~/*_hdf5_train.txt"
    batch_size: 32
  }
  include{phase: TRAIN}
}
layer {
  name: "data2"
  type: "HDF5Data"
  top: "Inputdata"
  top: "label"
  hdf5_data_param {
    source:"~/*_hdf5_test.txt"
    batch_size: 32
  }
  include{phase: TEST}
}
layer {
  name: "conv1"
  type: "convolution"
  bottom: "data"
  top: "conv1"
  param {lr_mult:1}
  param {lr_mult:2}
  convolution_param{
    num_output: 20
    kernel_h: 1
    kernel_w: 5
    stride_h: 1
    stride_w: 1
    weight_filler {
      type: "xavier"     
    }
    bias_filler {
      type: "xavier"
    }
  }
}
layer {
  name: "pool1"
  type: "pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param{
    pool: MAX
    kernel_h: 1
    kernel_w: 2
    stride_h: 1
    stride_w: 2
  }
}
# more layers here...
layer{
  name: "loss"
  type: "SigmoidCrossEntropyLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}