且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何按星期几在星期天在oracle 10中分组的年份日期或日期?

更新时间:2023-01-28 21:18:02

Assuming that day_date is a datetime field and that you want to display the start of the week as the grouping field, try a query of the form:

select TRUNC(day_date)-TO_NUMBER(TO_CHAR(day_date,'D'))+1 week_start_date,
       MAX(column2), MAX(column3)
from yourtable
group by TRUNC(day_date)-TO_NUMBER(TO_CHAR(day_date,'D'))+1;

If day_date is a text field representing a date in the format yyyy-mm-dd, you will need to replace day_date in the query above with to_date(day_date,'yyyy-mm-dd') throughout.

相关阅读

技术问答最新文章