所有季度,SQL 10年的PAS月份

发布于 2025-01-26 10:58:33 字数 347 浏览 3 评论 0原文

我想在过去的10年中使用查询来检索所有季度 -

SELECT TO_CHAR(sysdate, 'yyyy" Q "')||level AS QuarterDate 
   FROM dual
CONNECT BY level <= 4 

使用上述查询,我​​将获得当年的四分之一。我想过去十年。

Similary,是否有一种方法可以在过去10年中以同样的方式获得所有几个月的时间

SELECT DISTINCT to_char(sysdate, 'yyyy / mm') from dual

,是否有一种方法可以超越整个10年。

I want to retrieve all the quarters in the past 10 years using the query -

SELECT TO_CHAR(sysdate, 'yyyy" Q "')||level AS QuarterDate 
   FROM dual
CONNECT BY level <= 4 

Using above query I will get quarter for current year. I want for past 10 years.

Similary, is there a way to get all months in past 10 years in the format-

SELECT DISTINCT to_char(sysdate, 'yyyy / mm') from dual

Similarly, is there a way to get past all 10 years.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携余温的黄昏 2025-02-02 10:58:33

您可以使用Trick相同的连接来生成数年,几个月,几个月,几个月,日期等:

select
    to_char(y.n) || '/' || to_char(m.n)
from
    (select 1900+level as n from dual connect by level <= 500) y,
    (select level as n from dual connect by level <= 12) m
where
    y.n between 2012 and 2022

您还可以使用广泛的格式代码生成大量的日期和过滤/格式化/格式化/格式化:

select
    to_date('1900-01-01', 'YYYY-MM-DD') + level as d
from
    dual
connect by
    level < 100000

you can generate years, months, quarters, days, etc using the same connect by trick and just joining them together:

select
    to_char(y.n) || '/' || to_char(m.n)
from
    (select 1900+level as n from dual connect by level <= 500) y,
    (select level as n from dual connect by level <= 12) m
where
    y.n between 2012 and 2022

You can also just generate a large set of dates and filter/format the ones you want using the extensive format codes:

select
    to_date('1900-01-01', 'YYYY-MM-DD') + level as d
from
    dual
connect by
    level < 100000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文