Requirement of the strange

Oracle 11.2.0.1
Windows xp

Assume that this is the data in the table:
ID      AMT
24     65
18     48
19     88
27     39
16     15
12     52
32     22
26     13
11     77
15     91
40     27
And someone enter a number assumes that 104, output should be:
ID      AMT     FLAG
24     65     11
18     48
19     88
27     39     11
16     15
12     52
32     22
26     13     33
11     77     22
15     91     33
40     27     22
Reason: because in the above-mentioned amount, there are 2 possibilities of the sum of 104 that is 65 + 39, flag line should be 11 (medium 2 lines first) and 77 + 27 (22 ways, 2nd time 2 rows) and assume that there are 3 ID including the sum becomes 104 all the ranks of flag should be (333). Now suppose that the figure rises to 105 and there is no permutation to be 105 so, flag of all lines should be "000".

Requirements for companies: our billing service generated these bills and the amount in the entire day shift. In the evening, all invoices are sent to ship the Department. After receiving invoices, shipping contacts Ministry of production unit and here they receiving random packets of the amounts. In the aftermath of the day, they inform just a number in the billing department in last night, we sent amount N of transport invoices (more information will be sent by the Department of transport to the Bill on the next 4-5 days). Now, billing department wishes to proceed to a new day and they have just a number for example assume that 104. So, before you start the new bills for the following day, the data in table of previous days should be flaged.

I don't know how to do this, although kindly tell me how can I start to write the SQL and PL/SQL please.

Thank you.

Published by: user12050217 on May 30, 2012 10:43

Hello

To list the combinations possible of ID with a sum of AMT = 104 use the query below.

with a (id, amt) as
(
select 24,     65 from dual union all
select 18,     48 from dual union all
select 19,     88 from dual union all
select 27,     39 from dual union all
select 16,     15 from dual union all
select 12,     52 from dual union all
select 32,     22 from dual union all
select 26,     13 from dual union all
select 11,     77 from dual union all
select 15,     91 from dual union all
select 41,     123 from dual union all   --added for testing only
select 42,     99 from dual union all    --added for testing only
select 43,     104 from dual union all   --added for testing only
select 40,     27 from dual
)

,b (wanted_sum) as
(select 104 from dual)

,c as
(
select
  level number_of_ids
  ,trim(leading ',' from sys_connect_by_path(id,',')) ID_LIST
  ,dbms_aw.eval_number(trim(leading '+' from sys_connect_by_path(amt,'+')) ) tot
from
  (select a.* from a, b where a.amt = b.wanted_sum or a.amt <= b.wanted_sum - (select min(a.amt)from a) )

connect by
  id > prior id
)

select
  number_of_ids
  ,id_list
from
  c
  ,b

where
  c.tot = b.wanted_sum
;

NUMBER_OF_IDS ID_LIST
------------- ------------------------
            2 11,40
            3 12,26,27
            2 15,26
            2 24,27
            1 43

I hope this helps.

Kind regards

Peter

Tags: Database

Similar Questions

  • Make the field required using the Validation

    Hello

    I use R17 and want to make a field required by the adding validation [< field >] IS NOT NULL

    Strangely, this does not work on a new Record. a NULL value is always accepted. It only works for a modified record.

    has anyone in front of it too? or is this a BUG in my environment.

    Any ideas?

    Just to check if it works, I tried a [< field >] validation IS NULL and it worked correctly on New and updated records.

    Thank you
    Royston

    Hello

    There is a solution to achieve this. PL download the configuration steps of the below mentioned link.

    http://DL.dropbox.com/u/3971519/make%20A%20Field%20Required%20Using%20Advanced%20Field%20Management.doc

    Let me know if you have any questions.

    Rgds,
    Amit samir

  • Requirement of the weird - please help

    Hello

    I have a strange Req where the client wants a two new fields (news, URL) on the new Applet on the Home Page that can store text data.

    The problem is that these data are not related to any other entity. From now on, I've implemented functionality by extending the S_USER table for two new columns. But I am in real doubt on this approach because of these two reasons:

    1. whenever I create a new Record in the news and URL fields, all the required columns for the S_USER must be filled with values. That sounds weird because it will have to fill it with some dummy values.
    2. Secondly the S_USER table is used by the other British Colombia which will result in corrupted data that we fill in dummy values in the table S_USER.

    Can someone suggest an alternative approach where I don't have to deal with two problems above?
    Is there any other table that I can extend that will not suffer my changes.

    Thanks :)

    Hello

    There are several ways you can address the issue based on the customer's requirements:
    Scenario 1:
    News and URL fields are unique for all users.
    Steps to follow:
    1 S_USER_PROF table to store the details of NEWS and URL areas by extending the table.
    2. create a new business component based on the S_USER_PROF table and map the necessary level required DB columns and your NEWS and URLS in the fields.
    3. create a link between the S_USER and business components. S_USER_PROF use S_USER field Id and the Parent line Id field in S_USER_PROF for the binding configuration.
    4. create a new applet and expose the fields required in the applet and put this applet in the display of the Home Page.

    Scenario 2:
    News and URL are not unique, and multiple users can have the same new data and URLS:
    In this scenario, you will need to create two custom tables, one for more information news and URL, and the other will be the table of the Intersection.
    Steps to follow:
    1. create two tables in Siebel Tools. Say CX_NEWS_URL and add the required columns. Then create Intersection Table CX_USER_NEWS. In this table maps columns USER_ID with foreign key as S_USER and news_id has been with foreign key as CX_NEWS_URL.
    2. create a business component based on the CX_NEWS_URL table and create a link with the user and your BC. Be sure to specify the Inter of Table and column details.
    3. then create an applet MVG of your new BC and a MVF in users of BC.
    4 display the MVF field in your custom UI cmdlet.

    I would recommend is not to create fake users because it can cause problems in maintenance, and also when the user wants to delete the record of news and URL there will be questions.
    Hope I've been able to respond to your request.

    With the best regards,.
    Yassine jegou

  • How can I uninstall Sierra &amp; return to El Capitan without an external hard drive or equivalent required by the instructions online?

    How can I uninstall Sierra & return to El Capitan without an external hard drive or equivalent required by the instructions online? I find too many misadventures and not happy.

    Hello

    Check out this useful tutorial: https://www.igeeksblog.com/how-to-downgrade-macos-sierra-to-mac-os-x-el-capitan/

  • The requirements for the universal Clipboard not correct?

    Hello

    The requirements for the universal Clipboard for iMac is not correct. It should work on my iMac mid 2011, but it doesn't. It works on my Macbook Air mid-2013, so I know it works in general.

    You do not discuss Apple in these forums, we are all users like you.

    If you have any questions please ask, however if you have any comments for Apple please leave at www.apple.com/feedback.

  • How can I find the number of pixels is in my photos of the ipad? I sell on ebay and they have new requirements for the photos. 500 pixels on the longest side. Is it possible to increase the pixels on already took pictures?

    How can I find the number of pixels is in my photos of the ipad? I sell on ebay and they have new requirements for the photos. 500 pixels on the longest side. Is it possible to increase the pixels on already took pictures?

    See if this application works for you > https://itunes.apple.com/us/app/image-size/id670766542?mt=8

  • At least one number and one letter in English are required in the password.

    At least one number and one letter in English are required in the password.

    Page of the router is not fully displayed

  • The amount of space (memory) required for the good functioning of Firefox?

    The amount of memory required for the operation of Firefox? Trying to decide between IE and Firefox. Research in the new computer and need to think about which browser to use, and how much space it needs to work properly.

    You need no more than 40 MB for the operation of Firefox.

  • where the requirements for the current download? This used to be posted prominently.

    where the requirements for the current download? This used to be posted prominently.

    See:

    You can find the full version of the latest version of Firefox 24.0 in all languages and for all systems operating here:

  • Tecra A10 does'nt recognize 2nd HARD drive in the Bay of the STRANGE

    Hello

    My TECRA A10 - 1 HG PTSB1E does'nt recognize my second HDD that has taken the place of the cd-rom.
    I use a SATA caddy and the boot of the A10 with a CD-rom error!
    is it not possible to use a shopping cart with a TECRA A10?
    Does anyone have a solution?

    Thank you for your experience of return.
    Best regards

    Hello

    I guess that the Tecra A10 does not support these updates.
    The 2nd SATA controller does not seem to support the additional HDD instead of ODD.

    But I've read a few things to get such2nd as recognized HARD drive.
    You must start the laptop without the HARD drive caddy in ODD Bay.
    After that the Windows system has started, you can plug/connect the HARD drive caddy and system PnP service should recognize the new device.

    I think this isn't the best solution, but it seems like it s the only way to get this HDD caddy recognized in the Bay of the STRANGE

  • During the installation of Firefox 4 beta, he told me that it does not work on my Mac. When I go to system requirements, need a page for Firefox3.6 requirements. Where can I find the requirements for the beta?

    The link to the minimum configuration for Firefox 4 beta takes you to a page that gives you the requirements for Firefox 3.6 instead. I guess that the requirements for the beta are different, that I can't seem to install the beta on my Mac. Where can I find the beta version of system requirements?

    Firefox 4 will not work on the Mac PPC, for Mac it needs the Intel processor. There is an accumulation of third parties based on Firefox 4 beta, which should work on Mac PPC, for details, see http://www.floodgap.com/software/tenfourfox/

  • DDL required for the complete installation was not found. Error 1603. What should do?

    DDL required for the complete installation was not found. Error 1603. What should do? A link where to download the required DLL? Kindly help please.

    I tried everything, but received the same message. Attached to the screenshot.

  • Satellite A200-12 x PSAECE: can't see the STRANGE in my computer

    Hi all

    After using my toshiba recovery cd, I lose the CD/DVD-ROM drive, what's wrong?
    The laptop works fine, except that on this issue, I can't see the drive on my computer and equipment, and if I press the eject button I have no answer to the reader, even the amber does ' t see the light.

    I have Toshiba A200-12 x PSAEC (PSAECE) with Windows Vista 32 bit.

    Hope someone can help me please!

    Thank you

    Hello

    I think that Akuma means remove the STRANGE of the Bay of notebooks, then plug it in again.

    In any case, in my opinion you should first check if the reader of CD/DVD (ODD) was recognized in the BIOS, and maybe you can also try to boot from the CD/DVD drive to check the functionality.

    If it will work, the connection is ok.

    In this case, I would recommend removal of the upper and lower registry filters.

    Check the MS doc for more details:
    http://support.Microsoft.com/kb/270008/en-us

    Good luck

  • Im trying to load the update of Mac OS x Server combined software and it says that my disk volume does not meet the requirements of the software

    Im trying to load the update of Mac OS x combined Server software on my Mac Pro Tower 10.7.5 worm and it says that my disk volume does not meet the requirements of the software? Has anyone ever come across this problem?

    You are running a Mac OS X Server software? If so, which version?

  • I plan to upgrade my OS to El Capitan.  What are the processor speed and memory required for the operating system works well?

    I plan to upgrade my OS to El Capitan.  What are the processor speed and memory required for the operating system works well?

    I use a processor 2.3 GHz Intel Core i5 with DDR3 4 GB 1333 MHz memory.

    My last similar attempt on another machine resulted in a very slow computer.

    Thanks, Ron

    Apple says the following:

    General requirements

    • OS X 10.6.8 or later version
    • 2 GB memory
    • 8.8 GB of available storage

    For best performance, I would say not less 4 GB and preferably 8 GB or more.

    Your i5 is well able to support properly.

    http://www.Apple.com/OSX/how-to-upgrade/#Hardware Configuration

Maybe you are looking for