写了一条带条件判断的数据库语句例如:
SELECT if((a-b)<=0,0,(a-b)) as c from xxx
意思就是我想判断select a-b as c from xxxx,如果a-b<=0,c=0,如果a-b>0,就c=a-b
这种在mapper里怎么写啊是用标签在select后面直接写么?
sql语句怎么写,mapper里就怎么写,你这个用when case写。
select (case when a-b>0 then a-b else 0 end) as c from xxx
<select id="selectC" resultType="java.lang.Integer">
select (case when a-b > 0 then a-b else 0 end) as c from xxx
</select>