随笔分类 -  Sql学习

oracle 列转行函数listagg、判断函数decode
摘要:1、decode 使用decode判断字符串是否一样 DECODE(value,if1,then1,if2,then2,if3,then3,...,else) decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 某些场景可以代替case when 2、listagg 阅读全文

posted @ 2020-03-26 13:28 平平无奇杨小兵 阅读(730) 评论(0) 推荐(0)

case when嵌套
摘要:如果该列字段有为空的值,那么根据另一个字段值去判断结果,可以使用嵌套case when select p.id, p.pay_no, p.pay_status, case when nvl(p.check_result,'-1')='-1' then case when p.pay_status = 阅读全文

posted @ 2020-03-23 11:26 平平无奇杨小兵 阅读(17663) 评论(0) 推荐(0)

sql多表关联更新—用b表字段来更新a表对应的字段
摘要:在开发时,如果遇到表需要加字段,那么需要对存量数据刷新这个字段值 1、mysql --两张表关联 UPDATE JC_COLL_REPAY r INNER JOIN lc_lm_loan l ON r.loan_no = l.loan_no SET r.loan_typ = l.tep_cde, r 阅读全文

posted @ 2020-03-20 14:51 平平无奇杨小兵 阅读(1165) 评论(0) 推荐(0)

按某一列分组并筛选时间最新的一条记录
摘要:方法一: -- 方法1 select a.* from table a where not exists(select 1 from table b where b.id_no=a.id_no and b.crt_time>a.crt_time) 方法二:子查询 -- 方法2 select a.* 阅读全文

posted @ 2020-03-18 16:35 平平无奇杨小兵 阅读(235) 评论(0) 推荐(0)