欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql多条件匹配模糊查询

程序员文章站 2024-03-01 16:56:58
...
  // mysql版 
select * from nf_massif where
        concat(IFNULL(id,''),
        IFNULL(plot_number,''),
        IFNULL(respective_region,''),
        IFNULL(land_name,''),
        IFNULL(land_area,''),
        IFNULL(geographic_coordinates,''),
        IFNULL(land_type,''),
        IFNULL(land_price,''),
        IFNULL(land_condition,''),
        IFNULL(suitable_crop,''),
        IFNULL(lease_term,''),
        IFNULL(tenant,''),
        IFNULL(create_time,''),
        IFNULL(update_time,''))

        like CONCAT ('%吉阳%','%实验室%')

//mybatis版

  select * from nf_massif where
        concat(IFNULL(id,''),
        IFNULL(plot_number,''),
        IFNULL(respective_region,''),
        IFNULL(land_name,''),
        IFNULL(land_area,''),
        IFNULL(geographic_coordinates,''),
        IFNULL(land_type,''),
        IFNULL(land_price,''),
        IFNULL(land_condition,''),
        IFNULL(suitable_crop,''),
        IFNULL(lease_term,''),
        IFNULL(tenant,''),
        IFNULL(create_time,''),
        IFNULL(update_time,''))
        like CONCAT ('%', #{content},'%','%', #{hotZone},'%')

//注意:多条件时,范围大的条件放在前面,范围小的条件放在范围大的条件的后面,一旦颠倒,范围大的条件将不起作用