LoginSignup
0
0

期間マスタからのデータの取得方法

Posted at
WITH current_date AS (
    SELECT CURRENT_DATE AS today
),
current_fiscal_year AS (
    SELECT
        CASE
            WHEN EXTRACT(MONTH FROM today) >= 4 THEN EXTRACT(YEAR FROM today)
            ELSE EXTRACT(YEAR FROM today) - 1
        END AS fiscal_year_start
    FROM current_date
),
fiscal_year_dates AS (
    SELECT
        fiscal_year_start,
        TO_DATE(fiscal_year_start || '-04-01', 'YYYY-MM-DD') AS fiscal_year_start_date,
        TO_DATE((fiscal_year_start + 1) || '-03-31', 'YYYY-MM-DD') AS fiscal_year_end_date
    FROM current_fiscal_year
)
SELECT *
FROM period_master pm
JOIN fiscal_year_dates fyd
ON (pm.start_date <= fyd.fiscal_year_end_date AND pm.end_date >= fyd.fiscal_year_start_date);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0