<select id="querySchByCondition"resultMap="BaseResultMap">
SELECT a.*,b.NAME from a
LEFT JOIN b on a.CODE = b.ID
<where>1=1<if test="sch.startDate != null and sch.startDate != ''">
AND a.DATE >= CONCAT(#{sch.startDate}, ' 00:00:00')</if><if test="sch.endDate != null and sch.endDate != ''">
AND a.DATE <= CONCAT(#{sch.endDate}, ' 23:59:59')</if></where>
ORDER BY a.DATE asc
</select>
Oracle的相关SQL
case when的使用
select PATIENT_NAME as name,CASEWHEN(GENDER ='男性')THEN1WHEN(GENDER='女性')THEN0ENDAS GENDER, BED as bedNo
from PATIENT
between and和日期连用
select DEPT_CODE deptCode,count(*) count from PATIENT
where OUT_TIME BETWEEN TO_DATE(#{beginTime}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(#{endTime}, 'YYYY-MM-DD HH24:MI:SS') groupby DEPT_CODE
like和concat连用
select*from PATIENT
where NAME like concat(concat('%',#{name}),'%')
MySQL的相关SQLgroup by返回多列select DEPT_CODE deptCode,DEPT_NAME deptName,DEPT_TYPE deptType from PATIENT where ID in (select max(ID) from PATIENT group by DEPT_CODE) order by DEPT_CODEmybatis中使用转义字符(不用between and是因为其不包含右边界)其中 lt: 小于 ,gt: 大于<sele