Home » SQL & PL/SQL » SQL & PL/SQL » selecting random rows with selected fields that adds up to a specific value (oracle sql ...pl/sql)
selecting random rows with selected fields that adds up to a specific value [message #432310] Mon, 23 November 2009 09:07 Go to next message
marvSQL
Messages: 13
Registered: February 2008
Location: JAMAICA
Junior Member

i am working with a table similar to the one below:

-------------------------------
person | amount
-------------------------------
p1 | 100
p1 | 150
p1 | 600
p1 | 100
p1 | 300
p1 | 200
p1 | 50
p1 | 100

i want to get any row or combination of rows where the [amount] field adds up to 300
eg:
( 300 ) or (100,100,100) or (100,200) or (100,50,150) etc

is there any function available that can achieve this?

i would really appreciate any assistance.

[Updated on: Mon, 23 November 2009 09:57] by Moderator

Report message to a moderator

Re: selecting random rows with selected fields that adds up to a specific value [message #432320 is a reply to message #432310] Mon, 23 November 2009 09:59 Go to previous message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
No, there is not.

As this is a classical (but not obvious) homework, post what you tried.

Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Previous Topic: EXECUTE IMMEDIATE 'Create table'
Next Topic: reconfigure a col by sql command
Goto Forum:
  


Current Time: Sat Feb 08 20:55:37 CST 2025