mysql 操作记录,在必要条件下,添加多种条件的查询功能sql

这个再大佬看起来有点low ,但是这个 加深了我去 sql 的理解.
场景是:查询医生,药师。 搜索条件可以是,名称,科室,职位,等等....
SELECT
	modepartme1_.`name` as mname,
	doctor0_.id AS col_0_0_,
	doctor0_.NAME AS col_1_0_,
	doctor0_.doctor AS col_2_0_,
	doctor0_.pharmacist AS col_3_0_,
	doctor0_.goodOdds AS col_4_0_,
	doctor0_.introduce AS col_5_0_,
	doctor0_.labelIds AS col_6_0_,
	doctor0_.answerCount AS col_7_0_,
	doctor0_.imgUrl AS col_8_0_,
	doctor0_.medicalInquiryPrice AS col_9_0_ 
FROM
	Doctor doctor0_
	CROSS JOIN MODepartment modepartme1_ 
WHERE
    -- 这里有前提条件
	(doctor0_.moDepartment_id = modepartme1_.id and doctor0_.pharmacist = 1 and doctor0_.STATUS = 1)
	-- 这里是各种 子条件.如:查询 医生的名称,或者科室,或者 职位,或者 介绍.
	and (doctor0_.NAME LIKE '%产%' or modepartme1_.NAME LIKE '%产%' or doctor0_.specialty LIKE '%产%' or doctor0_.position LIKE '%产%' or doctor0_.introduce LIKE '%产%')
	
ORDER BY
	doctor0_.lastActiveTime DESC 

思路:

  1. 先满足必要条件。
  2. 把各种,或者 (or)条件包起来 ,再 当做一个 必要的查询条件.

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值