Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the pit encountered in Oracle calculation week compared with the same period last year

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to solve the pit encountered in Oracle Computing week". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

System environment: windows2008 Oracle 10g

The demand for the report is to require weekly year-on-year data, for example, January 1, 2021 is Friday, then the year-on-year date must also be Friday, January 3, 2020, and so on.

My way is, according to the current date, first take the year of the same period, then take the week of the whole year, and finally take the day of the week.

The original SQL statement is written:

WHERE date > = (SELECT date field FROM Table WHERE TO_CHAR (date field YYYY') = TO_CHAR (ADD_MONTHS (TRUNC (SYSDATE-1, 'mm'),-12),' YYYY') AND TO_CHAR (date field D') = (SELECT TO_CHAR (TRUNC (SYSDATE-1, 'mm')) 'd') FROM dual) AND TO_CHAR (date field-1 'ww') = (SELECT TO_CHAR (TRUNC (SYSDATE-1,' mm')) 'ww') FROM dual)) AND date = (SELECT Date field FROM A table WHERE TO_CHAR (date field YYYY') = TO_CHAR (ADD_MONTHS (TRUNC (SYSDATE-1, 'mm'),-12),' YYYY') AND TO_CHAR (date field D') = (SELECT TO_CHAR (TRUNC (SYSDATE-1, 'mm')) 'd') FROM dual) AND TO_CHAR (date field-1 'ww') = (SELECT TO_CHAR (TRUNC (SYSDATE-1,' mm')) 'ww') FROM dual)) AND date

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report