数据测试常用SQ

设置变量@
set @data = ‘2021-04-01’ //需要执行才能生效
select * from table where data >=@data

–查询数据库重复数据
select 筛选字段,count(1) from 表 (where查询条件) group by 筛选字段 having count(1)>1
select t.vin,count(1) from TM_CUSTOMER_VEHICLE t where MEMBER_AUTO_FLAG =‘1’ group by vin having count(1)>1

不等于有 <> 和 i =
其中当值为null时 != 不能识别出来

group by 优先于order by 所以想用order by 排序时,排序字段必须在group by查询出来的结果里
limit 显示行数排序在 order by 之后

round函数用于四舍五入
select date,max(user_num) PCU,ROUND(avg(user_num)) ACU from minute_online_user group by date order by date desc

处理数据
sum(case when 条件 then 统计字段 end)
round( data, 4) 小数保留位数

转换数据类型:常用于转字符串
cast(b.user_num as char) acuser_num

设置默认返回值:
COALESCE(data ,0) 处理返回结果为空情况,接口默认返回0

获取绝对值:
ABS()

---------------------------常用SQ
select table_name from all_tab_columns where column_name like’%DP%’–根据列字段查表名
select * from tab where tname like ‘%SGMSENLOG%’ --根据表字段查表名
update 表名 SET 字段=值(更新后的值)where 字段=值(需要更新的值) --更新数据
insert into from 表(字段) value 插入信息 --增加数据
delete from 表名 where 条件 --删除数据
DISTINCT --数据库字段去重(用在select后面)
select * from table where rownum<=10 --显示前10行数据:rownum 伪列
select * from table limit 10 --显示前10行数据
–查询在某段时间的数据
SELECT * from 表 where to_char(排序字段时间,‘yyyy-mm-dd hh:mi:ss’)>=<‘2012-05-07 09:42:59’
SELECT * from 表 where 排序字段时间>to_date(‘2018-11-29’,‘yyyy-mm-dd’)
SELECT * from 表 where 排序字段时间>sysdate(当前时间)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值