SQL常用的使用日记

一、sql实现相除保留2位小数

select * from A where round(A.count/A.last_count,2) > 0.25

二、sum函数返回为空,如何默认返回为0

select COALESCE(SUM(A.total),0) from A

三、获取多条数据中的第一条

select * from A where rownum = 1

四、替代case when then else的简单写法

select decode(u.sex,0,'未知',1,'男',2,'女') from users u 

五、多条记录,转成1条逗号分隔的形式

select WMSYS.WM_CONCAT(u.id) from user u

六、获取两个时间的天数差

select trunc(sysdate)-trunc(create_time) from dual;
select to_date(trunc(sysdate)) - to_date(trunc(create_time)) from dual;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值