您的位置:首页 >使用oracle如何计算连续数据的长度
发布于2024-12-02 阅读(0)
扫一扫,手机访问
select
nbr,
max(case when tot=2 then 1 else 0 end) as ls_2,
max(case when tot=3 then 1 else 0 end) as ls_3,
max(case when tot=4 then 1 else 0 end) as ls_4,
max(case when tot=5 then 1 else 0 end) as ls_5,
max(case when tot=6 then 1 else 0 end) as ls_6
from
(
select
nbr,
count(1) tot
from
(
select
nbr,
d_month
add_months(d_month, -1 * rn + 1) inter_val
from(
select
nbr,
d_month,
在这个例子中,“dense_rank() over (partition by nbr order by d_month) rn”是一个SQL语句中的一个窗口函数。它用来计算给定列(nbr)的密集排名,并按照指定的列(d_month)进行排序。它将返回一个新的列(rn),其中包含每个nbr的密集排名。
from
tmp_01
) a
) b
group by nbr,inter_val
)c
group by nbr;
在Oracle中,可以使用substr函数来截取字符串的一部分。如果截取的长度超过了字符串的实际长度,substr函数会返回整个字符串的长度。
用法举例:
使用 `substr()` 函数可以从指定的字符串中提取子字符串。该函数的语法如下: ``` substr( string, start_position, [ length ] ) ``` - `string`:要提取子字符串的原始字符串。 - `start_position`:开始提取子字符串的位置。索引从 0 开始计数。 - `length`(可选):要提取的子字符串的长度。如果未指定该参数,则将提取从 `start_position` 开始到原始字符串的末尾的所有字符。 例如,如果要从字符串 `Hello, World!` 提取子字符串
取得字符串中指定起始位置和长度的字符串
如:
如果我们使用substr('This is a test', 6, 2),那么返回的结果将是'is'。这是因为substr()函数可以从给定的字符串中提取一个子字符串,第一个参数是原始字符串,第二个参数是开始提取的位置,第三个参数是要提取的字符数。在这个例子中,我们从第6个字符开始提取2个字符,即'is'。
substr('This is a test', 6) would return 'is a test'.
substr('TechOnTheNet', -3, 3) would return the substring 'Net'.
substr('TechOnTheNet', -6, 3) would return 'The'.
SELECT SUBSTR('Thisisatest', -4, 2) AS value FROM dual
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
4
5
6
7
8
9