我遇到了这样的问题:
从今天到圣诞节还有几个月?
SQL> SELECT MONTHS_BETWEEN (TO_DATE('2013/10/14', 'YYYY/MM/DD'),
2 TO_DATE('2013/12/25', 'YYYY/MM/DD')) AS MONTHS_BETWEEN FROM DUAL;
MONTHS_BETWEEN
--------------
-2.3548387
现在我有这个问题:
名为 Flag Football Game 和 Guest Speaker 的 EVENT 之间有多少个月?
我无法弄清楚的问题是相关日期在同一列中(FLAG FOOTBALL 为 1,GUEST_SPEAKER 为 2)。此外,它们来自一张桌子,而不是像“双重”这样的非实体。
也许有一种方法可以在选择语句中嵌套一个“WHERE”子句,例如:
Select TO_CHAR(EVENT_DATE(WHERE EVENT_NAME = UPPER(‘Flag FOOtball Game’)
– TO_CHAR(EVENT_DATE(WHERE EVENT_NAME = UPPER(‘GUEST SPEAKER’)AS
TIME FROM FOOTBALL_TO_SPEAKER;
这是事件表:
SQL> select * from event;
EVENT_ID CLASS_ID EVENT_NAME EVENT_DAT T RAIN_DATE
---------- ---------- ------------------------------ --------- - ---------
1 9 ASTRO Physics STAR GAZING 09-NOV-99 O
2 10 Flag FOOtball Game 19-JAN-99 O 20-JAN-99
3 1 Guest SPEAKER 01-DEC-99 I
4 8 Barney ViDeo 01-SEP-99 I
5 10 PICKUP SOCCER GAME 09-JUL-99 I 10-JUL-99
6 2 Guest Speaker 20-NOV-99 I
我需要做什么?