特殊sql记录

获取时间最新的一条数据

select applyNo, MAX( createdAt) as time  from recall_record where applyNo in(select applyNo from recall_case WHERE updatedAt > '2022-11-29 22:00:00' and updatedAt <'2022-11-29 22:05:00') GROUP BY applyNo

行转列

select sum(decode(name,'action',num)) action_,sum(decode(name,'alarm', num)) alarm,sum(decode(name,'di',num)) di,sum(decode(name,'list',num)) list from
(
select
'action' name,
count(1) num
from
SG_RPAM_PRO_ACTION
union all
select
'alarm' name,
count(1) num
from
SG_RPAM_PRO_ALARM
union all
select
'di' name,
count(1) num
from
SG_RPAM_PRO_DI
union all select 'list' name,count(1) num from SG_RPAM_PRO_RECORD_LIST)

按天检索数据无数据补0

select
t1.date_ref,
case when t2.num is null then 0 else t2.num end as num
from (select to_char(to_date('2017-11-09', 'yyyy-mm-dd')+level-1, 'yyyy-mm-dd') date_ref from sysdba.sysdual connect by level<8) as t1
left join
(
select
count(1) num,
to_char(to_date(record_time, 'yyyy-mm-dd'),'yyyy-mm-dd') date_act
from
SG_RPAM_PRO_RECORD_LIST
where
record_time between '2017-11-09' and '2017-11-15'
group by
to_char(to_date(record_time, 'yyyy-mm-dd'),'yyyy-mm-dd')
) as t2
on
t1.date_ref=t2.date_act

查看数据库锁表情况

select * from information_schema.innodb_trx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值