subqueries, nested, using elements of the other party of the request

Hi all
I have a delicate problem, and I'll try to explain my best:

DB version is 11.2.0.3.0
create table product_list (product_id number,
                project_name varchar2(30))

create table products (product_id number,
                project_desc varchar2(30))

create table total_counts (product_id number,
                total_count number,
                project_name varchar2(30))

create table fixed_counts (product_id number,
                fixed_count number,
                project_name varchar2(30).
                    fixed_date date)
                    
create table product_rating (product_id number,
                rating number,
                quarter_last_updated number)
                    
create table quarters (quarter_id number,
                quarter_end_date date)


insert into product_list values (1, 'Prod 1');
insert into product_list values (2, 'Prod 2');
insert into product_list values (3, 'Prod 3');

insert into products values (1, 'Prod 1');
insert into products values (2, 'Prod 2');
insert into products values (3, 'Prod 3');

insert into total_counts values (1, 2000, 'Prod 1');
insert into total_counts values (2, 1000, 'Prod 2');
insert into total_counts values (3, 500, 'Prod 3');

insert into fixed_counts values (1, 1, 'Prod 1', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (1, 3, 'Prod 1', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (2, 50, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (2, 2, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (2, 3, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (2, 3, 'Prod 2', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (3, 8, 'Prod 3', to_date('01/01/2013','DD/MM/YYYY'));
insert into fixed_counts values (3, 3, 'Prod 3', to_date('01/03/2013','DD/MM/YYYY'));

insert into product_rating values (1, 1, 1);
insert into product_rating values (3, 2, 2);

insert into quarters values (1, to_date('01/10/2012','DD/MM/YYYY'));
insert into quarters values (2, to_date('01/02/2013','DD/MM/YYYY'));
My current query joins actually 2 tables 'TOTAL_COUNTS' and 'FIXED_COUNTS '. The FIXED_COUNTS table is updated every day when a product has a patch against it and the query returns a list of all products and their "fixed" rate percentage (used in an interactive report of the APEX).
select A.PRODUCT, A.TOTAL, B.FIXED, a.PROD_ID, round((FIXED/TOTAL) * 100,  2) percent
from (
select sum(a.total_count) TOTAL, a.product_id PROD_ID, d.Product_desc PRODUCT
from total_counts a, product_list c, products d
where a.product_id = c.product_id
and lower(a.project_name) = lower(c.project_name) 
and c.product_id = d.product_id
group by a.product_id, d.product_desc
) A
JOIN 
(
select sum(b.fixed_count) FIXED, b.product_id PROD_ID, d.Product_desc PRODUCT
from fixed_counts b, product_list c, products d
where b.product_id = c.product_id
and lower(b.project_name) = lower(c.project_name) 
and c.product_id = d.product_id
group by b.product_id, d.product_desc
) B
on A.PROD_ID = B.PROD_ID and A.PRODUCT = B.PRODUCT 
It gives me a result like:
PRODUCT     TOTAL     FIXED     PROD_ID     percent
Prod 1     2000     4     1     0.2
Prod 2     1000     58     2     5.8
Prod 2      500     11     3     2.2
The application works very well and does exactly the job I need. However, I now a requirement that when a product gets a percentage rate 'fixed' more than 1% of the product gets a point added against her in a table 'product_rating' and I have to recalculate the percentage of the date, the item has been added (so no points added we take all 'fixed').

To do this, I added 2 new tables: "product_rating" and "quarters". The "product_rating" table contains the Product_id and points, he has accumulated so far. It is updated once a quarter. 'Quarters' table simply contains the dates for us to use for calculations again.

Actually, I need to replace this:
sum(b.fixed_count) FIXED
with something like this:
if a product has a point against it in the "product_rating" table then we just show fixes from the date the point was added i.e. 
select sum(b.fixed_count) from fixed_counts b, product_rating c, quarters d
where b.product_id = c.product_id and c.quarter_last_updated = d.quarter_id
and b.product_id = PROD_ID
and b.fixed_date > (select quarter_end_date from quarters where quarter_id = the_last_quarter_updated)
Based on the values in the tables above the percentages for "3 Prod' should now be 0.6.» It is because he received a product_rating the quarter 2, then the new calculation is based on all the "corrections" after this date (only the last March 1 13').

I tried many ways to integrate this into the current query, but I can't make it work. Sorry for not adding the info from the entire table, but the tables total_counts and fixed_counts have many more columns that I removed the query so it would be easier to observe. Thanks in advance for your help. If I can add more info ask please.
Tom

Published by: on May 14, 2013 TomH 08:54

Published by: on May 14, 2013 TomH 08:58

TomH wrote:
of course, to the right, thank you.
I added some info table and data that will hopefully a little easier to understand.

OK, thank you... to the future but please try and run the commands yourself for you sure they work. What you provided is close, but it has not executed immediately without modifications.

I will start by expressing my concerns for your data model, it seems... well, for lack of a better word. Although you said you deleted a bunch of stuff to make the example. You have someone, you you work who can look at the model for you?

With respect to the query, it's not pretty (I'm in a bit of a rush here) so you can probably clean it considerably. I just tried to show the basics of what you're going to have to do.

ME_XE? with base_data as
  2  (
  3     select
  4        b.fixed_date,
  5        b.fixed_count,
  6        b.product_id ,
  7        d.project_desc
  8     from fixed_counts b, product_list c, products d
  9     where b.product_id = c.product_id
 10     and lower(b.project_name) = lower(c.project_name)
 11     and c.product_id = d.product_id
 12  ),
 13     final_base_data as
 14  (
 15     select
 16        b.product_id      PROD_ID,
 17        b.project_desc    PRODUCT,
 18        sum
 19        (
 20           case
 21              when b.fixed_date >= stuff.quarter_end_date or stuff.quarter_end_date is null
 22              then
 23                 b.fixed_count
 24              else
 25                 0
 26           end
 27        )  as FIXED
 28     from base_data b
 29     left outer join
 30     (
 31        select
 32           pr.product_id,
 33           qr.quarter_end_date
 34        from product_rating pr , quarters qr
 35        where pr.quarter_last_updated = qr.quarter_id
 36     )  stuff
 37     on (stuff.product_id = b.product_id)
 38     group by b.product_id, b.project_desc
 39  )
 40  select A.PRODUCT, A.TOTAL, B.FIXED, a.PROD_ID, round((b.FIXED/a.TOTAL) * 100,  2) percent
 41  from
 42  (
 43     select sum(a.total_count) TOTAL, a.product_id PROD_ID, d.project_desc PRODUCT
 44     from total_counts a, product_list c, products d
 45     where a.product_id = c.product_id
 46     and lower(a.project_name) = lower(c.project_name)
 47     and c.product_id = d.product_id
 48     group by a.product_id, d.project_desc
 49  ) A
 50  JOIN final_base_data B
 51  on A.PROD_ID = B.PROD_ID and A.PRODUCT = B.PRODUCT
 52  ;

PRODUCT                                     TOTAL              FIXED            PROD_ID            PERCENT
------------------------------ ------------------ ------------------ ------------------ ------------------
Prod 1                                       2000                  4                  1                 .2
Prod 2                                       1000                 58                  2                5.8
Prod 3                                        500                  3                  3                 .6

3 rows selected.

See you soon,.

Tags: Database

Similar Questions

  • Hello out there! I am trying to understand the relationship between the products. I am a current user of 13 items and sought to CC Photoshop with Lightroom. Always use elements like the storage tool to catalog my photos or it get replaced?

    Hello out there! I am trying to understand the relationship between the products. I am a current user of 13 items and sought to CC Photoshop with Lightroom. Always use elements like the storage tool to catalog my photos or it get replaced?

    It's kind of ridiculous. All I want to do is ask a question and there is no place to connect with anyone. Sucks!

    Hi charlesf,

    If you choose to go to CC Photoshop with Lightroom, Photoshop Elements would not be replaced.

    CC of Photoshop and Photoshop Elements are different programs, so the two will remain separate on your machine and catalogue items would not hit at all.

    Let us know if you have any other questions.

    Kind regards

    Claes

  • using elements of the table in the order?

    Hello

    I created a table which includes four-part numbers. I want to stimulate each element one after the other. After the creation of my program, I see that only the first element of the array is enabled, but not the other RAS.

    I actually use this program to stimulate the four different smells. I join all of the program that controls the olfactometer and the framework of this program that I have problems with.

    If any of you have any idea how I can solve the problem and can use all different smells/elements during the experience?

    Sincerely,

    Samia Alam.

    You have a double case of 'localitite' and 'sequencetitus '.  No need to use local variables and structures of the sequence.

    Use wire instead of local variables where you can.  If wire you your table type of Stimulation through the wall of the loop, you can set it for automatic indexing.  This means that each loop iteration will use each element of the array in turn.  Then you won't need the Index array function, or need to wire a 4-Terminal N of the loop.

    (Otherwise, we could plug your i of iteration loop Terminal to the terminal of the index of the Array Index function.)

  • Using elements in the field and the transfer of my computer at home?

    I want to use my ultrabook with elements in the field in order to sort, shoot, and edit the images in time.  When I go home can I just transfer these files from my computer at home and use Get Photos to add them to my main catalog?  Tags, version sets and changes made in the field will survive, so that it would be the same if I had done this treatment on my computer at home in the first place?

    Here is a more detailed workflow suggestion, assuming you want to do the bulk of your organization in the computer field.

    It is based on the notes above and the use of a backup PSE to transfer photos and catalog of the field at home a computer.

    -Create a new catalog on your computer in the domain before you download files.

    -organize entirely unconstrained...

    -Prepare a later import in your main catalog, after the backup and restore processes (details to come...) or wait until after the restoration to make this work.

    -Backup to a disk external (there are beautiful portable USB drives in ideal for this)

    -(Note: quand vous avez votre sauvegarde, il est sûr de re-formater vos cartes.)

    -Restore from the external hard drive to your computer at home (custom destinatin). You will have a new catalogue with all your changes.

    -If you did not already preparing indicated above, it is here. Select the files in the batteries and common as label "IsInAStack", and then select the version games and assign a label like "IsInAVersion". Now, you can also assign keywords to the components of cells. For albums, use the common keywords. If you need save the order in albums (for slideshows...) export and rename the files as explained above and reimport them in your catalog.

    -Now you can re - import the files in your main catalog

    -To re - create batteries select files with "IsInAStack" or their label and either stack manually or with the help of the feature automatically 'suggest piles. Sets of version can be restored only like batteries. Albums must be recreated: you drag the selection based on the keyword corresponding to the album.

  • Using elements of the application of interactive report filters

    Hello

    Can we use elements of application in interactive report filters? If so, how?

    Thank you
    Machaan

    Take a look at the creation of a link to the section of interactive reports in the Application Guide of the user for example generator

    This example binds, resets and clears the saved report parameters 12345. It also creates an ENAME = 'KING' filter on saved report 12345.

    f? p = 100: 1: & SESSION. : I have R_REPORT_12345::RIR, CIR::RIR, CIR:IR_ENAME:KING

    If you have an element of the application P1_ENAME the following apply to the example above

    f? p = 100: 1: & SESSION. : I have R_REPORT_12345::RIR, CIR::RIR, CIR:IR_ENAME: & P1_ENAME.

    If you want a permament for all filter saved reports on the value of point of application, it is best to use the: APP_ITEM_NAME bind variables in your SQL syntax, it really depends on how you define the value of your item and how you interact with it. AFAIK does not request point directly bind variables syntax in the filters, IR etc...

  • Effective rate using ni6143 with the request based on aiex2.cpp method

    Dear engineers experienced,

    I had a problem with the request method based on the file "aiex2.cpp", available on the site by using ni6143. It comes to the actual sampling rate. On the datasheet, it is said that the ni6143 could have the ability to data acquisition with speed of 250 kHz per channel, which means that each data could be acquired in 4th-6 second. So here's my question: if I use all 8 channels (each to 250 kHz), this means that I have to use 8 [channels] * 4th-6 [seconds] = [seconds] to get a data set (one for each channel), 32nd-6 or I can use only 4-6 [seconds] to get? I use the method of application based on aiex2.cpp for the experience of the trial. Inorder to check exactly what is the sampling rate, I/o digital set up a signal in the maximum power before gain on demand and set low during data acquisition is complete. It shows the oscillograph than the actual time for the acquisition of a set of data (one for each channel) when I use 8 channels (each to 250 kHz) is about 32-6 [seconds], which means that the device acquires data by a channel channel, not at the same time. I want to know if there is any setting that I have to settle with the registers, or request method could not acquire data with 8 channels simultaneously. My code is exactly the same with the file "aiex2.cpp".

    Thanks for help.

    Hello Licry,

    Yes, the example only shows how to acquire a number fixed samples.  Among the function calls that implements the acquisition will allow you to make the material constantly acquire...

    aiNumberOfSamples (theSTC, numberOfSamples, kFalse); for finite, false for continuous

    If you can set it to kTrue to acquire continuous.  So that the task to continue to work, your application must be able to access the FIFO data fast enough so that it does not overflow.

    Second, every continuous acquisition must end someday.  When your loop has acquired all data affecting the application, he must issue commands to stop the acquisition.  The manual of the STC in detail the steps that can be taken to stop a continuous acquisition.

    http://www.NI.com/PDF/manuals/340934b.PDF (see section 2.4.3.3)

    Steven T.

  • using values of element in the request

    Hello


    Is there a way I can use the item values in the query...?

    for example, something like that

    Select a.*,: P20_CUST_NAME as client_name
    Of
    TEMP table;

    have not yet tried but want to get feedback first before attempting...

    Thank you

    Yes, provided that this element has a value in session state...

    Thank you

    Tony Miller
    Webster, TX

  • loop nested using iteration of the outer loop as counter

    Hello world.  I have a moment where I perform calculations at each iteration of the loop and display on the front panel.  Then, in a loop iteration randomly (referred to here as I = 9 to test) it fires an event where that performs calculations on x number of iterations (iterations of the outer loop while) the result of external calculations, while performing at the same time and the view from the outside so that the calculations of the loop.  Is that two mathematics algorithms are synchronized in iterations.  After x iteration the program returns then to only calculate and display the while loop calculations using the value from the shift register, updated until another event is triggered (I do not show an another event trigger in the code example) I can just find a way to trigger an event , and at the same time to make two calculations with the same loop iterations.  Any suggestions?

    The VI of the sample in the previous post of crossrulz should provide the functionality you are looking for. The while loop acts to go through ten operations you want to perform and records time difference will allow him to record these values, as you understand. I think that crossrulz refers to shift registers on the while loop that surrounds the case structure that records the shift are unusable on a structure of the case, as you pointed out.

  • Cannot control the sequence of elements in the poster, using JDev 10.1.3.4

    Who who know or have known the same front:

    I use JDev 10.1.3.4 to develop my application. I interspersed with JSF, and ADF elements in my pages the elements of the model. Sometimes I managed to work around this problem, sometimes it can control just not it. Here is an excerpt from a page:
    <p>Some text before the radio buttons</p>
    
    <h:selectOneRadio binding="#{backing_student_doValidation.selectOneRadio1}"
            id="selectOneRadio1">
    <f:selectItem itemLabel="I Agree" itemValue="agree"
            binding="#{backing_student_doValidation.selectItem1}"
            id="selectItem1"/>
    <f:selectItem itemLabel="I Disagree" itemValue="disagree"
            binding="#{backing_student_doValidation.selectItem2}"
            id="selectItem2"/>
    </h:selectOneRadio>
    
    <p>Please click the Submit button to Continue.</p>
    
    <h:commandButton value="Submit"
            binding="#{backing_student_doValidation.commandButton1}"
            id="commandButton1"/>
    But the page does not appear in this order:
    Some text before the radio buttons
    
    
    
    Please click the Submit button to Continue.
    
    O I Agree    O I Disagree
    [Submit]
    Note that option buttons ignore paragraph down to retreat with the submit command button.

    I choose to use .jsp to my pages. It seems that the problem occurs when the ADF is involved in the page. I deliberately avoid using jspx and adf panelPage because panelPage restricted menu bars and facets etc which I did not need and it is impossible to remove. I use therefore with jsp pages and html jsp tags to make the pages simple and clean. But I have to use elements of the data control palette; and once everything is drag-and - drop to the design of the page editor, adf tags tab will be automatically added to the page and two troubling things are happening: one is that the elements of the model are no longer visible in the Design tab of the page editor; the other is the problem shown above.

    Are there ways to get around the problem?

    Thank you very much!

    Newman

    Newmann,

    This happens because you mix HTML markup with the JSF tags (which you shouldn't do). You could try surrounding the pure html markup with f: tags verbatim or using JSF tags to generate your static output.

    John

  • Can I batch nest, multiple clips on the timeline?

    I have several clips in my calendar ~ 200 +.

    My final goal is to export them all out as separate clips.

    I understand that I must first nest each clip and then put them in a bin export to the SOUL from there.

    Problem is, I have to right-click on each item and select niche, then I must name it... so with 200 clips I have 400 shares to achieve this result.

    Issues related to the:

    1 is there a way I can automatically nest each element in the timeline so that they remain as separate clips?

    2. each nested element can cause a unique name such as 001,002,003, etc...

    Nest and naming.png

    Thank you in advance.

    Jeremy

    Mark the first clip, her tail.  Mark the second clip, he tail.  Go to the bottom of the line of the sequence for each clip.

  • How disbale at the request of concurrent programs

    Hello

    Our environment is:

    Apps:R12,
    OS: Linux

    You must disable some unwanted concurrent requests and some games request to disable. How to disable the concurrent requests to the application, we


    and we want to run Gather stats wise scheme, so I think better to use all of the request, how we define, please let me know


    Thank you

    Hello

    You must disable some unwanted concurrent requests and some games request to disable. How to disable the concurrent requests to the application, we

    You can disable several regular simultaneous requests since the backend using the following query:

    SQL> update fnd_concurrent_requests
    set phase_code = 'C', status_code = 'X'
    where status_code in ('Q','I')
    and requested_start_date > SYSDATE
    and hold_flag = 'N'; 
    

    Note: 170107.1 - how to determine at the request of concurrent requests
    https://metalink2.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=170107.1

    Note: 152209.1 - What are the meanings of the Codes in the STATUS_CODE and the PHASE_CODE FND_CONCURRENT_REQUESTS Table columns?
    https://metalink2.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=152209.1

    Kind regards
    Hussein

  • Can not hear the other party

    Had a weird start this morning problem. If I dial a number, even on speaker, the Cliq says it connects, but I never hear ringing or anyone pick it up. It's complete volumes and the speaker.

    I don't have a landline to see if it sounds or not, but I called one of my own numbers that sounds twice and going straight to voicemail, so I know that something is definitely wrong. I think I can hear static and the other party, but it is so low, that it is difficult to say. It's my only phone, so it's kind of a critical issue!

    Troubleshooting tips, I can try?

    I recently started using Shush! I really hope that is not the cause, because it is an essential application for me.

    Thanks in advance!

    OK, a reboot fixed it. I just had it redial a number well. EEK! Gremlins!

    Anyone know why I might have had the problem?

    Thank you

  • When on Skype the other party sees my room mirrorwise

    Hello

    When you use Skype with camera, the other party sees me mirrorwise, so I wanted to fix it but couldn't get to the pn from the camera to my laptop.

    hope you can help me with this

    Wilma

    Have you checked the video settings in Skype?

  • Why am I called on my computer I hear the other party good, but they don't hear me

    several times I try tocalled on my computer, but the other party is me does not, but I hear them well as call on Skype yahoo, rynga and so many other

    Hi Bayo578,

    1. If it works much earlier?

    2. did you of recent changes on the system?

    You will need to check the parameters of the webcam or chat program that you use.

    See to believe

    You can also see the following articles for more information:

    https://support.Skype.com/en/FAQ/FA897/why-can-t-the-other-person-hear-me

    http://help.Yahoo.com/tutorials/Ms8/mess/im_callmanag2.html

    Hope this information is useful.

  • I do not hear, nor the other party can't hear me

    Tey as the webcam VX-2000, for the first time and I was not able to listen, nor the other party was able to hear me, what I do I have to do?

    Hello

    I suggest you to download the software from this link and install:
    http://www.Microsoft.com/hardware/en-us/d/LifeCam-VX-2000

    For installation problems, see this link:
    http://www.Microsoft.com/hardware/LifeCam/en-us/default.mspx

    It will be useful.

Maybe you are looking for

  • HP 15-b129wm: power on password for hp 15-b129wm

    Cannot circumvent the admin power on password for 15-b129wm

  • malware found after you run the ESET online scanner

    C:\Program Files (x86)\BabylonToolbar\BabylonToolbar\1.5.3.17\BabylonToolbarApp.dll a variant of Win32/Toolbar.Babylon application cleaned by deleting - quarantined C:\Program Files (x86)\BabylonToolbar\BabylonToolbar\1.5.3.17\BabylonToolbarEng.dll u

  • Module NI 9403 terminal State after the beginning of task

    Hi all We have some problems with a relay connected to the NI 9403 module card. There are probably a few Chin-ups correct definition outputs during the initialization of the 9403 (high logic out the relay). After feeding the 9403, no relay are activa

  • 4 quadrant TRIAC test circuit does not work

    Hello Attached, you will find a test for a TRIAC circuit. U1 must be set between 0 to 2, 7V (so the Ug voltage is between 0 and 0.85V). The goal is to know when the TRIAC gets to work. By changing the polarity U1 and U2, you could do this in all 4 qu

  • Windows Vista 32 bit Media player 11

    0 When trying to play music already purchased downloads the rights to the song but I can't play because the Start button is grayed out. Music has been a long time MSN Music .com and purchase location on another computer with xp operating system. No o