一个输入框搜索多个字段SQL
作者:互联网
例子图片
具体SQL:是使用concat..(不了解concat的使用就去简单看一下就懂了,简单的理解是字符串的拼接)
详细:
select *
FROM
biz_lis_request_information a
LEFT JOIN biz_lis_sample c ON a.barcode = c.barcode
<where>
<if test="patientId != null and patientId != ''">
CONCAT(IFNULL(a.patient_name,''),IFNULL(a.patient_id,''),IFNULL(a.barcode,''),IFNULL(a.request_doct_name,''),IFNULL(a.execute_doct_id,''),IFNULL(c.sample_no,'')) LIKE concat( '%', #{patientId}, '%' )
</if>
<if test="sendOrganizationId != null "> and a.send_organization_id = #{sendOrganizationId}</if>
<if test="barcode != null and barcode!='' "> and a.barcode = #{barcode}</if>
</where>
order by a.request_doct_date desc
详解:
CONCAT(IFNULL(a.patient_name,''),IFNULL(a.patient_id,''),IFNULL(a.barcode,''),IFNULL(a.request_doct_name,''),IFNULL(a.execute_doct_id,''),IFNULL(c.sample_no,'')) LIKE concat( '%', #{patientId}, '%' )
1.IFNULL:为空的结果取 ‘’
2.#{patientId}:图片中的查询字段
3.CONCAT(‘’‘’‘’‘不为空字段’)LIKE concat( '%', #{patientId}, '%' ) == patientId 通过模糊查询 ‘不为空字段’
4.(不了解concat的使用就去简单看一下就懂了,简单的理解是字符串的拼接)
标签:IFNULL,barcode,patientId,doct,输入框,字段,SQL,id,concat 来源: https://www.cnblogs.com/nkcell/p/15958784.html