Home » SQL & PL/SQL » SQL & PL/SQL » Query to find last 6 month records (oracle 10g)
Query to find last 6 month records [message #472621] Mon, 23 August 2010 01:24 Go to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
SELECT HISTORY_ID ,SUM(MISSED_SCHOOL) AS MISSED_SCHOOL,SUM(MISSED_SCHOOL_LAST) AS MISSED_SCHOOL_LAST
FROM EMRASTHAMAHISTORYDETAILS
WHERE ------
GROUP BY HISTORY_ID

There is no date column in table using sysdate alone need to retrieve last 6 month records

how to use in where condition
Re: Query to find last 6 month records [message #472622 is a reply to message #472621] Mon, 23 August 2010 01:30 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
If there is no date column /timestamp there is no way you can retrieve the data. How would you track the record if there is no date column specified?


Regards
Ved
Re: Query to find last 6 month records [message #472623 is a reply to message #472622] Mon, 23 August 2010 01:34 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You can do it in the same way you'd get the result per classroom color.

Regards
Michel
Re: Query to find last 6 month records [message #472624 is a reply to message #472622] Mon, 23 August 2010 01:37 Go to previous messageGo to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
i will create one column then what is the query please..created_date is my column is my date field
Re: Query to find last 6 month records [message #472626 is a reply to message #472624] Mon, 23 August 2010 01:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
477 posts, at least 2 years in SQL, and you still don't know if a date is in the last 6 months?

First, try to find the query that gives you the date 6 monthd back from now.

Regards
Michel

[Updated on: Mon, 23 August 2010 01:41]

Report message to a moderator

Re: Query to find last 6 month records [message #472627 is a reply to message #472624] Mon, 23 August 2010 01:41 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
You said,
Quote:

i will create one column


Very good! Smile Now, question is how you are going to assign the date for each record??


....and yes, if you had the data in date column then how would you do that? > This is a FAQ..similar kind of question is being posted every week.You just need to know where to find it when you need it.


All the best!

Regards
Ved

[Updated on: Mon, 23 August 2010 01:58]

Report message to a moderator

Re: Query to find last 6 month records [message #472682 is a reply to message #472627] Mon, 23 August 2010 04:23 Go to previous messageGo to next message
amit.sonar
Messages: 98
Registered: December 2009
Location: Mumbai
Member
Hi,

as per above scenario,if i enable audit on that table by access then is it possible to keep track of inserts statments perform on that table?

Thanks & Regards,
Amit Sonar.
Re: Query to find last 6 month records [message #472685 is a reply to message #472682] Mon, 23 August 2010 04:29 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
Yes but it wouldn't be much help for the query you want to do.
Might as well add a date column.
Re: Query to find last 6 month records [message #472687 is a reply to message #472682] Mon, 23 August 2010 04:31 Go to previous messageGo to next message
ThomasG
Messages: 3212
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
It might just be me, but any table that has "history" in it's name and not has a date column in it is pretty pointless.

And enabling audit to get the insert date is about as good as an idea like having everyone who does an insert write the date and the history ID on a post-it and file it in a desk drawer. As soon as someone deletes the audit trail, or upgrades the database of hardware or whatever the audit data will be gone.
Re: Query to find last 6 month records [message #472688 is a reply to message #472685] Mon, 23 August 2010 04:36 Go to previous messageGo to next message
amit.sonar
Messages: 98
Registered: December 2009
Location: Mumbai
Member
Hi,

This will work for future reords but what about existing records? Trigger is also one of the option. we can maintain one hist or temp table so no need to change table sturcture.

Thanks & regards,
Amit Sonar
Re: Query to find last 6 month records [message #472689 is a reply to message #472688] Mon, 23 August 2010 04:46 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
Since you don't know when the existing records were inserted you have two options:
1) Make up a date
2) leave the date null.

Don't understand what you mean about not needing to change the table structure.
Re: Query to find last 6 month records [message #472704 is a reply to message #472689] Mon, 23 August 2010 06:25 Go to previous messageGo to next message
amit.sonar
Messages: 98
Registered: December 2009
Location: Mumbai
Member
Hi,

It was regarding to Trigger. If I created after inser trigger On table and insert data into history table with timestamp then no need to add date column to exsisting table.

Thanks & regards,
Amit Sonar.
Re: Query to find last 6 month records [message #472706 is a reply to message #472704] Mon, 23 August 2010 06:42 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
So you're going to duplicate the data across 2 tables?
Re: Query to find last 6 month records [message #472712 is a reply to message #472687] Mon, 23 August 2010 07:45 Go to previous message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
ThomasG wrote on Mon, 23 August 2010 05:31
It might just be me, but any table that has "history" in it's name and not has a date column in it is pretty pointless.


Are you surprised, based on the dimwit who asked the question?
Previous Topic: Can we use Merge Statement here
Next Topic: Query
Goto Forum:
  


Current Time: Mon Aug 18 09:24:56 CDT 2025