嗯……碰到哪个写哪个,做个整理
1、decode
select decode(sex,1,'男','女') from student
意思就是在Student表中 sex下为1 则sex是男,否则就是女
2、时间格式
select to_char(date,'yyyy-MM-dd hh24:mi:ss') date from Time
查询的时间要以这种格式输出
3、isEquals用于动态拼接sql
-----------转自https://www.cnblogs.com/warrior4236/p/5978752.html
如下实例:
如果status的状态为0,则更新attribute1;状态为1,则更新attribute2;
状态为2,则更新attribute3
<update id="topup.doEffect" parameterClass="java.util.HashMap">
update cis_customer set code_id = #codeId# ,
<isEqual property="status" compareValue="0" prepend=",">
attribute1=#attribute1#</isEqual>
<isEqual property="status" compareValue="1" prepend=",">
attribute2=#attribute2#</isEqual>
<isEqual property="status" compareValue="2" prepend=",">
attribute3=#attribute3#</isEqual>
where id = #id#
</update>
4、isNotEmpty
----------------转自https://www.cnblogs.com/warrior4236/p/5978752.html
如下实例:
查询cis_customer这张表,如果属性aaa不为空,则将条件aaa=#aaa#拼接;
如果bbb不为空,则将条件bbb=#bbb#拼接;如果属性ccc不为空,则将条件ccc=#ccc#拼接;
<select id="topup.querySuccessCount" parameterClass="java.util.HashMap">
2 select id,name from cis_customer where 1=1
3 <isNotEmpty property="aaa" prepend="and">
4 aaa=#aaa#
5 </isNotEmpty >
6 <isNotEmpty property="bbb" prepend="and">
7 bbb=#bbb#
8 </isNotEmpty >
9 <isNotEmpty property="ccc" prepend="and">
10 ccc=#ccc#
11 </isNotEmpty >
12 </select>
5、order by
这个order by 是个比较基础的词,昨天在看的时候发现了个我不太熟悉的点,然后随手整理下来了。
select * from student order by age
这句是将Student表按age大小排序,没有写如何排序,则默认为升序(ASC)
select * from student order by age desc
这句是将Student表按照age大小排序,并且是按降序排序(DESC)
ASC
表示按升序排序DESC
表示按降序排序
上面的都是一个字段排序,下面来个俩的
select * from student order by age ,name desc
这句是将Student表先按照第一个age字段排序,如果在age字段升序排序不分先后的情况下,用name进行二次排序,此处name用的是降序
select * from st_password order by upper(password)
这句是将st_password 表下的password按升序排序并且区分大小写 。
select * from student order by age nulls last
这句呢就是讲Student表下按age进行升序排序,并且将值为null的放在后面
NULLS FIRST
在非NULL
值之前放置NULL
值,NULLS LAST
在非NULL
值之后放置NULL
值
--------------------先写这几个,更新ing