Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need to extract 15 months data using SQL select

3230967Jun 28 2016 — edited Jun 29 2016

Hi All,

I got a requirement to create a report that should extract past 15 months data from the database.

I have prepared the SQL script for reference.

  SELECT   TRUNC (table1.CREATE_DATE, 'MM'),

  table1.state_code,

  table2.detail,

   COUNT ( * )

   FROM  table1, table2

   WHERE  table1.state_code = table2.state_cd

   AND table1.CREATE_DATE >=

   (  SELECT   TRUNC ( (ADD_MONTHS (SYSDATE, -15)), 'MM') FROM DUAL)

   AND table1.CREATE_DATE <=

   (  SELECT   LAST_DAY (ADD_MONTHS (SYSDATE, -1)) FROM DUAL)

GROUP BY   TRUNC (table1.CREATE_DATE, 'MM'), table1.state_code, table2.detail


Is there anyother efficient way that I can achieve the same results.

Thanks in Advance!

Regards,

Ramya.

This post has been answered by Goran Stefanović on Jun 29 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2016
Added on Jun 28 2016
17 comments
3,764 views