Query to find last 6 month records [message #472621] |
Mon, 23 August 2010 01:24  |
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 #472627 is a reply to message #472624] |
Mon, 23 August 2010 01:41   |
Its_me_ved
Messages: 979 Registered: October 2009 Location: India
|
Senior Member |
|
|
You said,
Quote:
i will create one column
Very good!  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 #472687 is a reply to message #472682] |
Mon, 23 August 2010 04:31   |
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   |
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   |
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   |
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 #472712 is a reply to message #472687] |
Mon, 23 August 2010 07:45  |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
ThomasG wrote on Mon, 23 August 2010 05:31It 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?
|
|
|