User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 427,765 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,676 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser: Programming Forums
Views: 4616 | Replies: 2 | Solved
Reply
Join Date: Mar 2005
Location: Nebraska, U.S.
Posts: 190
Reputation: stupidenator is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

order and then compare values from same column

  #1  
Jan 26th, 2007
Hello everyone,

I am fairly new to oracle and SQL and I am having a little trouble figuring out how to accomplish a task.

I have three columns from a table, we will call them 'a', 'b', and 'id'. I first want to order by 'id' and then query the ordered data with the following condition.

I want to add the value at column 'a' to the value at column 'b' and then check and see if that sum is equal to the next value in column 'b'.

If that is not possible, I may also be able to add up column 'a' and column 'b' (take the sum of each column, grouped by 'id') and then subtract the last value in column 'a' grouped to each id from column 'a' and then compare the value of column a (sum(a) - last_value(a), with respect to the id from the 'id' column) with the sum of column 'b' (sum(b))

Any help would be appreciated!

Thanks,

Nick
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2006
Location: Mumbai, India
Posts: 351
Reputation: aniseed is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 5
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: order and then compare values from same column

  #2  
Jan 29th, 2007
This doesn't appear to be a task that can be performed with a single SQL if that was what you were looking for. Even if it is possible (because I'm not very good at SQL myself), the query itself is so dependent on the results that having a stored procedure and using a cursor would be a good choice.
Reply With Quote  
Join Date: Mar 2005
Location: Nebraska, U.S.
Posts: 190
Reputation: stupidenator is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: order and then compare values from same column

  #3  
Jan 31st, 2007
Thank you for your help. Below is what I eventually came up with as a solution.


SELECT UNIQUE id
FROM table1 a
LEFT JOIN table1 b
ON a.value1 + a.prev_value <> b.prev_value
WHERE to_number(b.amd_no) = (to_number(a.amd_no) + 1)
AND a.id = b.id;


Thanks,

Nick
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Oracle Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Oracle Forum

All times are GMT -4. The time now is 1:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC