Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

GETDATE() subtract a year

$
0
0
I am nearing the end of my current project and this question being one of my last is causing me trouble. I cannot implement the GETDATE() statement to my scenario.

Basically, I need to list some movie details and the download dates for all movies that were downloaded one year ago throughout the calendar month that matches todays month. So, if I were to run the query in November 2013, I would need results that show all downloads made in November 2012.

There are only two tables involved, M_DOWNLOADS that holds the download dates & M_MOVIES that holds movie details. I've pasted the CREATE TABLES sql for both tables below to help, but I do not know how the GETDATE clause works, and where it would go in my code.

What I need this query to do is show the DOWNLOAD_DATE from M_DOWNLOADS and, say,
TITLE_OF_MOVIE & DURATION_OF_MOVIE for now, from the M_MOVIES table.

M_DOWNLOADS

CREATE TABLE "M_DOWNLOADS"
( "DOWNLOAD_DATE" DATE,
"CUSTOMER_ID" VARCHAR2(10),
"MOVIE_ID" VARCHAR2(10),
CONSTRAINT "M_DOWNLOADS_CON" PRIMARY KEY ("DOWNLOAD_DATE", "CUSTOMER_ID", "MOVIE_ID") ENABLE
)
/



M_MOVIES

CREATE TABLE "M_MOVIES"
( "MOVIE_ID" VARCHAR2(10),
"TITLE_OF_MOVIE" VARCHAR2(20),
"DURATION_OF_MOVIE" NUMBER(3,0),
"CLASSIFICATION_CODE" VARCHAR2(10) NOT NULL ENABLE,
"DIRECTOR_OF_MOVIE" VARCHAR2(20),
CONSTRAINT "M_AVAILABLE_MOVIES_PK" PRIMARY KEY ("MOVIE_ID") ENABLE
)
/
ALTER TABLE "M_MOVIES" ADD CONSTRAINT "M_AVAILABLE_MOVIES_CON" FOREIGN KEY ("CLASSIFICATION_CODE")
REFERENCES "M_CLASSIFICATION_CODE" ("CLASSIFICATION_CODE") ENABLE
/

CREATE OR REPLACE TRIGGER "BI_M_AVAILABLE_MOVIES"
before insert on "M_MOVIES"
for each row
begin
if :NEW."MOVIE_ID" is null then
select "M_AVAILABLE_MOVIES_SEQ".nextval into :NEW."MOVIE_ID" from dual;
end if;
end;

/
ALTER TRIGGER "BI_M_AVAILABLE_MOVIES" ENABLE
/


Thanks, and I promise there'll be no more hassle from me anytime soon. ;)

Viewing all articles
Browse latest Browse all 13329

Trending Articles