当月的星期-间隔

时间:2018-10-29 11:23:21

标签: sql oracle date

如何从当前月份中每隔1./2./3./.4-5周(间隔)选择一次?

所以不喜欢:

select to_char(sysdate,'W') from dual

但是我需要间隔=当月的星期(例如oktober的2.week,因为它是10月-sysdate)。因此,具体来说:

select SUM(number)/((trunc(sysdate,'WW')/4) from my_table where date between ? and ? 

1 个答案:

答案 0 :(得分:0)

类似的东西应该对您有用。

SELECT TO_CHAR(datecol,'W') AS week, 
       SUM(countcol) AS sum_of_sales
FROM sales
  WHERE TO_CHAR(datecol,'YYYYMM') = TO_CHAR(SYSDATE,'YYYYMM') --current year and month.
  GROUP BY TO_CHAR(datecol,'W')
ORDER BY TO_CHAR(datecol,'W')