| | |
order and then compare values from same column
Please support our Oracle advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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
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
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.
Thank you for your help. Below is what I eventually came up with as a solution.
Thanks,
Nick
Oracle Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- compare values in a tuple/list (Python)
- Cmp?? (Assembly)
- Compare two tables (MS SQL)
- Can any1 help me...this is urgent (Java)
- I would kill for this, just a little bit (C)
- Create Windows Authentication (VB.NET)
Other Threads in the Oracle Forum
- Previous Thread: using jsp for a calendar connected to oracle
- Next Thread: Cartesian Product Problem
| Thread Tools | Search this Thread |
2009predictions acquisition amazon.com bartz bernanke cia citrix cloudcomputing crm database dell economy editor enterprise enterprise2.0 enterprisesoftware federalreserve forbes hp ibm intellipedia internet larryellison layoffs linux loughridge mediawiki michaeljackson microsoft neverland nortel notebooks oil operatingsystem oracle palm rimm saas salesforce sap seagate socialcomputing sql sun sybase technologystocks virtualiron virtualization vmware wiki wikipedia xen yahoo zoho





