【发布时间】:2018-09-14 09:03:52
【问题描述】:
查询应返回当前会计月份的天数。请检查以下查询:
SELECT *
FROM GL_PERIODS
WHERE PERIOD_SET_NAME='Fiscal Year'
AND period_year =(SELECT DISTINCT period_year
FROM gl_periods
WHERE TRUNC (SYSDATE) BETWEEN start_date
AND end_date)
对于时间段名称:SEP-19,开始日期为 8/26/2018。因此,sysdate 的天数应该是 16。
样本数据:
period_set_name period_name start_date end_date entered_period_name
Fiscal Year AUG-19 7/29/2018 8/25/2018 AUG
Fiscal Year SEP-19 8/26/2018 9/22/2018 SEP
Fiscal Year OCT-19 9/23/2018 10/27/2018 OCT
预期输出:16
【问题讨论】:
-
您的样本数据没有
period_year列,period_name与entered_period_name和end_date中的月份匹配,但与start_date和end_date中的年份不匹配。 -
如何得到
16的预期输出?今天的日期是2018-09-14,这是您的SEP期间的第 20 天(26 日至 30 日是 8 月的 6 天,9 月 1 日至 14 日是 9 月的 14 天)。
标签: sql oracle fiscal dayofmonth