所以我有一个查询将从表中获取一些日期,做一些操作来确定最新的日期,然后确定我是否必须检查过去7年或15年,然后有一个是/没有一行告诉我该怎么做。问题是我不太明白该怎么做。我环顾四周,似乎我可能需要在SELECT中使用SELECT,但似乎无法弄明白。我想我的语法不是点或什么的,表或视图不存在就是我现在所拥有的。
SELECT fact.NO_CONTRAT_OFFICIEL AS noContrat,
Case When to_date(fact.VSTDTCHG, 'yyyymmdd') < to_date(fact.VSTDICHK, 'yyyymmdd') And to_date(fact.VSTDTCHG, 'yyyymmdd') < to_date(fact.VSTDIFIN, 'yyyymmdd') Then to_date(fact.VSTDTCHG, 'yyyymmdd')
When to_date(fact.VSTDICHK, 'yyyymmdd') < to_date(fact.VSTDTCHG, 'yyyymmdd') And to_date(fact.VSTDICHK, 'yyyymmdd') < to_date(fact.VSTDIFIN, 'yyyymmdd') Then to_date(fact.VSTDICHK, 'yyyymmdd')
Else to_date(fact.VSTDIFIN, 'yyyymmdd')
End As TheMin,
Case When fact.NO_CONTRAT_OFFICIEL = virage.NO_CONTR Then sysdate - 15*365.25
Else sysdate - 7*365.25
End As Operation,
(SELECT NO_CONTRAT_OFFICIEL, Operation, TheMin,
Case When TheMin < Operation Then 'yes'
Else 'no'
End As yesno
From XC4DSAV facts) as yesnotable
FROM XC4DSAV fact
JOIN yesnotable T1
ON fact.NO_CONTRAT_OFFICIEL = T1.NO_CONTRAT_OFFICIEL
FULL OUTER JOIN STAR.EVENEMENT star
ON fact.NO_CONTRAT_OFFICIEL = star.NO_CONTRAT_DIFFUSE
JOIN VIRAGE.CONTRAT virage
ON fact.VSTNOCNT_VIRAGE = virage.NO_CONTR
WHERE fact.NO_CONTRAT_OFFICIEL IS NOT NULL;
答案 0 :(得分:0)
看起来您想要解释稍微大一点的查询。在这里,我已将其用作from子句中的视图,然后只需从中选择所需的列和计算。
SELECT noContrat, Operation, TheMin,
Case When TheMin < Operation Then 'yes'
Else 'no'
End As yesno
from (SELECT fact.NO_CONTRAT_OFFICIEL AS noContrat,
Case When to_date(fact.VSTDTCHG, 'yyyymmdd') < to_date(fact.VSTDICHK, 'yyyymmdd') And to_date(fact.VSTDTCHG, 'yyyymmdd') < to_date(fact.VSTDIFIN, 'yyyymmdd') Then to_date(fact.VSTDTCHG, 'yyyymmdd')
When to_date(fact.VSTDICHK, 'yyyymmdd') < to_date(fact.VSTDTCHG, 'yyyymmdd') And to_date(fact.VSTDICHK, 'yyyymmdd') < to_date(fact.VSTDIFIN, 'yyyymmdd') Then to_date(fact.VSTDICHK, 'yyyymmdd')
Else to_date(fact.VSTDIFIN, 'yyyymmdd')
End As TheMin,
Case When fact.NO_CONTRAT_OFFICIEL = virage.NO_CONTR Then sysdate - 15*365.25
Else sysdate - 7*365.25
End As Operation
FROM XC4DSAV fact
FULL OUTER JOIN STAR.EVENEMENT star
ON fact.NO_CONTRAT_OFFICIEL = star.NO_CONTRAT_DIFFUSE
JOIN VIRAGE.CONTRAT virage
ON fact.VSTNOCNT_VIRAGE = virage.NO_CONTR
WHERE fact.NO_CONTRAT_OFFICIEL IS NOT NULL)