Home » SQL & PL/SQL » SQL & PL/SQL » Need help with PLSQL query
Need help with PLSQL query [message #307709] Wed, 19 March 2008 11:08 Go to next message
sumit381
Messages: 2
Registered: March 2008
Junior Member
Hello, I am using Oracle 10g and I am having trouble with a query.

I have the following table called Data_Table:
Columns:
URI, CurrentStat, PastStat, Date_ID

The data in my table gets loaded with different Date_IDs representing the data loaded for that year(ex. DateID = 2 for year 2008, DateID = 1 for 2007, etc.). What I want to do in my query is return all rows where CurrentStat of last year's Date_ID does NOT equal PastStat of this year's Date_ID. This will be done by checking the URI for each record and making sure it matches when comparing records from different years.

Sample Data:
URI, CurrentStat, PastStat, Date_ID
123, 001, 002, 2
123, 003, 004, 1
123, 002, 004, 1
234, 003, 006, 2
234, 006, 072, 1

So if the query is run my output from the sample data should be:

URI, PastStat(current year), CurrentStat(past year)
123, 002, 003

Any help would be greatly appreciated.
Re: Need help with PLSQL query [message #307723 is a reply to message #307709] Wed, 19 March 2008 12:54 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9104
Registered: November 2002
Location: California, USA
Senior Member
You can do this with a self join. You can find syntax and examples in the online documentation. Please read the forum guidelines for the proper way to post future questions.

Re: Need help with PLSQL query [message #307724 is a reply to message #307723] Wed, 19 March 2008 12:57 Go to previous message
sumit381
Messages: 2
Registered: March 2008
Junior Member
Thank you for your help, but I already figured out how to do it.
Previous Topic: Update date
Next Topic: finding latest date in oracle
Goto Forum:
  


Current Time: Sat Feb 15 15:11:30 CST 2025