Get Total running under certain conditions

Dear gurus

I use Oracle Database 10 g Rel.2. I have a table of stock like that

Create table INV (number of Transaction_No,

Transaction_Date date,

Transaction_Type Varchar2 (50).

Department Varchar2 (50).

Varchar2 (50), point

Transaction_QTY Number (5));

Its data are like this:

Transaction_No Transaction_Date Transaction_Type Department Agenda Transaction_QTY
131 December 2013ReceptionProductionBolt100
2January 1, 2014ReceptionProductionBolt10
3January 1, 2014QuestionProductionBolt40
4January 2, 2014QuestionProductionBolt15
5January 3, 2014ReceptionProductionBolt5

Now I need output like that on January 1, 2014:

Transaction_No Transaction_Date Transaction_Type Department Agenda Opening Transaction_QTY Stock running
2January 1, 2014ReceptionProductionBolt10010110
3January 1, 2014QuestionProductionBolt1004070
4January 2, 2014QuestionProduction"BOLD"1001555
5January 3, 2014ReceptionProductionBolt100560

I have a function that calculates the opening quantity open QTY = Sum (Receipt) - Sum (Issue) before January 1, 2014.

If my request does not need calculation for the opening. He just has to add and subtract reception and show respectively 1 January 2014.

I used:

Decode (Transaction_Type, 'Réception',

My_Function (...) Opening_Value +.

Sum (Transaction_QTY) over (Partition by post, Transaction_Type

Rows between Unbounded Preceding

And Current Row)

«Question»,

My_Function (...) Opening_Value-

Sum (Transaction_QTY) over (Partition by post, Transaction_Type

Rows between Unbounded Preceding

And Current Row) Running_Stock

But that does not give my required return as described above.

So can u help me solve this query?

Try this one

SELECT i.Transaction_No,

i.Transaction_Date,

i.Transaction_Type,

i.Department,

i.Item,

My_Function (...) opening_value,

i.Transaction_QTY,

My_Function (...)

+ (SUM)

CASE

WHEN i.transaction_type = 'Réception' THEN i.Transaction_QTY

I.Transaction_QTY OTHER *-1

END)

COURSES (ORDER BY Transaction_Date, transaction_no) running_stock,

CASE WHEN i.transaction_type = 'Réception' CAN

SUM (i.Transaction_QTY)

COURSES (PARTITION BY transaction_type ORDER BY Transaction_Date, transaction_no)

ON THE OTHER

NULL VALUE

END running_receipt

CASE WHEN i.transaction_type = 'Edition' CAN

SUM (i.Transaction_QTY)

COURSES (PARTITION BY transaction_type ORDER BY Transaction_Date, transaction_no)

ON THE OTHER

NULL VALUE

END running_issue

Inv I have

"WHERE the transaction_date > = 1 January 2014"

Post edited by: Elya

Tags: Database

Similar Questions

  • Under certain conditions allow a Feedback

    We use integrated installation of APEX flow back. We love this feature but, we will only use it in development. Is that anyway, apart from the use of JavaScript to hide or remove the link, we can have this under certain conditions depending on the environment in which the application is running?

    I know we can go turn off in the properties of the Application, but we have a ton of environments and having to manually press this switch whenever get us a new version of the application becomes tedious. I expect something more by program / data driven. For example, is it possible to return this switch integrated with PL/SQL?

    Thank you

    -Joe

    Create a compilation Option. In the development environment has defined the status on Includeand by default on export to exclude.

    Apply the Option to build on the entry page and the navigation bar of your comments. When the application is imported into a different environment the comments link and the page will not be returned.

  • imaqReadAVIFrame retrieves the empty image under certain conditions?

    Hello

    I'm having a problem where imaqReadAVIFrame (.) is the white recovery (all black images) under certain conditions.  The conditions seem to be when the height of the AVI file is equal to or greater than the width and the height is an odd number.  AVI files created by using the various AVI NI Vision (IMAQ 4.6.1, IMAQdx 4.6.1) functions in an application created in CVI 2012 on a computer running Windows 7 64 bit.  AVI files use MJPEG compressor, and they play back fine in an external program like VLC or Windows Media Player.  Any ideas on what this could be?  My solution for now is to not to allow the creation of AVI files where the height is odd and equal to or greater than the width that is not a boring restriction, but it seems like there's something weird happens with imaqReadAVIFrame().  I can provide some AVI files if necessary, but they are 16 + MB each.

    TStanley,

    I managed to reproduce what you see with your .avi files in a program I wrote.  I built a LabVIEW program that creates an AVI file which can be saved to memory and then uses code from the example finder to read who created the file.  I build the file to your specifications at the height is greater than the width, and the height being an odd number of pixels.  Something interesting about this, however, is that it seems to be a point where an odd height is acceptable.  Once you go below the height of 291 pixels, any odd height then works.  The files that I used are written as read in LabVIEW, but that the configuration should be irrelevant because we are seeing the same issue.  In addition, LabVIEW and LabWindows CVI calling the same dll to actually set up the code.

    In this, I think this question arises from the nature of the way you compress the. AVI file.  If you are interested to read a bit more about it, a useful link can be found here:

    http://www.manifest-tech.com/media_pc/avi_formats.htm

    However, what I think is happening, is it that MJPEG file compression format translates into creating files that cannot be read by our software unless the height in pixels is a multiple of 2 or the size of the file is below a certain limit.  To fix that, there is a simple solution. Compress the file with any of the other compression methods available (DV video, Cinepak Codec, codec Intel IYUV, Microsoft RLE, Microsoft Video) and you will be able to open the file without the black screen.  This worked for me and should solve all your problems.  I hope this gives you a bit of insight.

    Kind regards

    Keith M

    Technical sales engineer

  • How can I add a page under certain conditions?

    Hello

    I'm trying to find a way to add a page to my form under certain conditions. I tried to create this sequel to 'action', but failed to locate the correct action.

    To sum up, I am trying to add a separate page to my existing form with instructions when a specific check box is selected. The separate page is text only and does not form any entries/field. Is there a relatively simple way to accomplish this task?

    You can enter the code in the script editor. If you do not show you can get it by pressing on (on PC) Ctrl + Shift + F5.

  • Under certain conditions create script

    Hi, I want to put a redirect code in my stsytem to help, it is possible to build under certain conditions one < script type = "text/javascript" > tag?

    Any help would be great appricieated

    oooo and meta tags as well!

    You are wanting to add a Javascript within a topic and then conditionalise it so it appears only in some outings? If so, check out this part of the aid for the addition of scripts. Once it is in, you should be able to add a tag of conditional compilation to exclude required results.

    I'm not sure you can conditionalise however meta tags. Maybe if you elaborate a bit on what you're trying to reach.

  • Under certain conditions see the popup on page (fragment) charge

    Hi Experts,

    We have an obligation to show a popup on the page load, if a certain condition is true.

    I have two fragments (home.jsff and profile.jsff). Initially when the user login, home.jsff is indicated and that there should be no popup.

    When the user goes to profile.jsff and save the changes, it must first redirect to home.jsff and show a popup with the confirmation message.

    I can't create a fragment separated for the popup where we need to redirect to profile.jsff and then redirect to home.jsff as said the requirement that the popup should display the content of home.jsff in the background.

    Also I can't use showPopup behavior during the loading of the page because it's a jsff.

    Please suggest how to implement this.

    Thanks in advance.

    Best regards

    Saurabh

    ... There's an even simpler option

    1. Add a hidden from the fragment output text element

    2 bind the output components text 'value' property to a bean property of manage (pair of getter/setter)

    3. when the getter of the value method is called, check the indicator that you defined for if you want to display the context menu or not

    4. If the indicator is such that the popup needs to be displayed, run the Java Popup

    4.a search the component RichPopup

    4.b set flags of the popup

    4.c unset flag to display the pop-up window (for the next time you need to put it)

    4.d see the popup

    Frank

  • hide the text label in the section report IR under certain conditions

    Hello
    We have a textlabel and a calculated field in a section of report to the IR 11.1.2.1. Is it possible (in a script) to hide the textlabel and field based on certain conditions, like for example, if the field computes to 'zero '?
    Thank you.

    Use a field instead of the text label. In the Expression Editor you can use the function if() {} else {}

    HTH

    Wayne

  • Get the next row in the set of results under certain conditions

    Hello
    I have a result set with a column in ascending order of the numbers. Now, I want to compare these numbers to a value. If one of the numbers exactly matches the value then all is well and I use number < = value as a condition. If the value does not match exactly I want to get the next number in the result as well. A short example

    NB in resultset
    41
    82
    123
    164
    205
    246

    To compare with value = 200, I want to have

    41
    82
    123
    164
    205

    as a result.

    To compare with value = 164, I want to have

    41
    82
    123
    164

    Thanks for any advice.
    Carsten cordially

    You can use analytical functions for that. There are several options, here is one.

    with testdata as (select 41 num from dual union all
                      select 82  num from dual union all
                      select 123 num from dual union all
                      select 164 num from dual union all
                      select 205 num from dual union all
                      select 246 num from dual)
    /* end of test data creation */
        ,resulttab as (select num, nvl(lag(num) over (order by num) ,0) next_num
                       from testdata )
    select num
    from resulttab
    where next_num < 200 ;
    NUM
    ---
    41
    82
    123
    164
    205
    
    ...
    select num
    from resulttab
    where next_num < 164 ;
    41
    82
    123
    164
    
  • Get the value of the following line in the game ordered under certain conditions

    Do not know if my best subject line sums up what I do :)


    Oracle DB 12 c (I think 12.1.2)


    I have a table with the names of people and DOB with a few keystrokes. It is assumed that this person is the 'same' first_name, last_name, birth_day/month/year are identical

    drop table people;

    create table persons

    (

    first name varchar2 (30),

    VARCHAR2 (30) last_name,.

    birth_month varchar2 (2),

    birth_day varchar2 (2),

    birth_year varchar2 (4).

    keyVal number

    );

    insert into values('JOHN','SMITH','10','10','1974',1) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('JOHN','SMITH','10','10','1974',2) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('JANE','SMITH','10','10','1974',3) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('JANE','DOE','10','10','1974',4) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('JANE','DOE','10','10','1974',5) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('ERIC','DOE','11','10','1975',6) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('ERIC','DOE','11','10','1975',7) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    insert into values('ERIC','DOE','11','10','1975',8) people (first_name, last_name, birth_month, birth_day, birth_year, keyval);

    I want to see the following output:

    first_name, last_name, birth_month, birth_day, birth_year, keyval_min, keyval_other

    JOHNSMITH101019741 2
    JANEDOE101019744 5
    ERICDOE111019756 7
    ERICDOE111019756 8

    1. the output will display only those who appear at least twice in the original table

    2. If the person appears twice in the original table, the output will only one result where first keyval will be min two; second keyval will be the other value;

    3. If the person has 3 times or more (n times, for example), each line of output will be keyval_min of all keyvals followed by the other value keyval. Total of n-1 lines

    It's very large 100 + M and the processing time is important.

    Hope I explained it well.

    Hello

    This sounds like a job for analytical functions.

    If the same person has N rows in the table, the output should be N - 1 lines.  You can use the ROW_NUMBER analytic function to assign numbers (1, 2, 3,...) to each line and do not display the lines nuimbered 1.

    On each line, you must prove the keyval lowest for this person.  The analytical MIN function can do this.

    Here's one way:

    WITH got_analytics AS

    (

    SELECT first_name, last_name, birth_month, birth_day, birth_year, keyval

    , ROW_NUMBER () OVER (PARTITION BY first_name, last_name, birth_month, birth_day, birth_year)

    ORDER BY keyval

    ) AS r_num

    , MIN (keyval) OVER (PARTITION BY first_name, last_name, birth_month, birth_day, birth_year)

    ) AS keyval_min

    AMONG the people

    )

    SELECT first_name, last_name, birth_month, birth_day, birth_year

    keyval_min

    keyval AS keyval_other

    OF got_analytics

    WHERE r_num > 1

    ORDER BY first_name, last_name, birth_month, birth_day, birth_year

    r_num

    ;

    Use the data DATE to the date information type.  With the help of 3 columns separate NUMBERS will result in complicated, ineffective, code errors and invalid data.

  • Under certain conditions the filling of a column (country code) according to the context

    This is the task given to me

    I have conditionally to the filling of a column (country code) based on the context selected in ODI


    What is this mean and how to get a solution for this

    No, the context is not that.
    Context is an environment. For different implementations, it may be different. Let me share how we use them.
    We use 4 contexts - DEV (development), INT (integration), TCT and the PRD.
    Each interface can be run in any context. The ODI will provide information from schema/information of physical server during execution to the enforcement process depending on what context has been chosen.
    The executions in the following contexts can be controlled using the ODI Security Module.

    Other implementations I've seen are that each context represents a different location (server) of the company. Thus, interfaces can be run on different machines depending on the configuration. ODI translates this information during execution.
    Context1 (Server1) may be used to run an interface1 during the day and Context2 (Server2) may be used to run the interface1 overnight.

    In your case, it seems that each frame is another country. So, depending on the context, the field must be filled in by the country_code.

    PS don't forget to award the useful points or correct answers that helped you.
    Thank you

  • How can I activate under certain conditions a timed pulse?

    Hello

    I need to repeatedly pass a system to test.  To do this, I need to take six switches entry.  When they are all active, I need to generate a digital high about 1 second in time to restart the cycle.  I have to do this 1000 times.

    I have a loop that displays a True value when the six input switches are closed.  The problem is to get that signal to generate a second pulse on my DAQ and increment a counter of some sort.

    Once more, a task that you could train a chimpanzee to do in five minutes takes me hours to understand in LabView.

    Running LabView 8.6 with one NOR cDAQ-9172.  Digital NI 9423, output digital input module is a NI 9472.

    Since you have already a Boolean output, simple solution like just this wiring up an instruction box with the DAQmx written inside. Because the module is timed, you write a logic, a software, wait and then write a logic 0.

    If the simple solution below is not what you need, please provide details. Join your code would help.

  • Can hide us a view particular criteria under certain conditions

    Hello

    In our application, we want to have multiple criteria of view that will be displayed in the query Panel and table of the JSF page. But the display criteria are controlled based on user roles.

    So we want to hide certain criteria of view for any particular user who should not use this criterion of the view. On the object view if we change a criterion for the view and go to UI tips tab there is a 'Show on list' option which when checked/unchecked will show/hide criteria in the saved search drop down. I want to do the same thing programmatically based on condition.

    I'm not find examples of it.

    If anyone has done this before or would help pointers examples or documentation.

    I use JDev - 11.1.2.4

    Thank you

    Finally found the solution to my requirement-

    How to hide the viewcriteria from the Panel of af: query | They show me the finger... again!

    Exactly what I was looking for.

  • Under certain conditions, update a table based on the comparison with a SQL statement

    I have a table (table 1) that has 4 columns:

    UID. THE NEST | VALUE1 | VALUE2

    I have another statement SQL (STMT) that returns the 3 columns of a few other tables:

    UID. THE NEST | VALUE1

    Now this is the condition of the way in which I want to put up-to-date TABLE1:

    First, to compare a pair of UID and PID of STMT with those in TABLE1,

    -1, for any new pair UID and PID not in TABLE1, insert a new line of STMT in TABLE1 set TABLE1. Value2 = 0 (I already did this).

    2, for an existing UID and PID pair in STMT and TABLE1, do:

    a. in TABLE1. Value2 > 0, update TABLE1. VALUE1 = STMT. VALUE1

    b. to TABLE1. Value2 = 0 and if TABLE1. VALUE1! = STMT. Value1, update of TABLE1. VALUE1 = STMT. Value1, otherwise nothing to do.

    I can't seem to come with a solution for condition 2. Any help is appreciated!

    Hello

    Here's one way:

    MERGE INTO  table1  dst
    USING          (
                 SELECT  ...   -- your stmt query goes here
             )   src
    ON         (    src.uid  = dst.uid
             AND      src.pid  = dst.pid
             )
    WHEN MATCHED THEN UPDATE
    SET           dst.value1 = CASE
                                   WHEN   dst.value2 > 0
                        OR     (   dst.value2 = 0
                             AND dst.calue1 != src.value1
                        )
                        THEN   src.value1
                               END
    WHERE   dst.value2 > 0
    OR (    dst.value2 = 0
       AND  dst.calue1 != src.value1
       )
    ;
    

    This assumes that the combination (uid, pid) is unique in stmt. It doesn't have to be unique in table1.

    sb92075 wrote:

    -1, for any new pair UID and PID not in TABLE1, insert a new line of STMT in TABLE1 set TABLE1. Value2 = 0 (I already did this).

    FUSION could also do parts 1 and 2 together, in the same statement.

    2, for an existing UID and PID pair in STMT and TABLE1, do:

    a. in TABLE1. Value2 > 0, update TABLE1. VALUE1 = STMT. VALUE1

    b. to TABLE1. Value2 = 0 and if TABLE1. VALUE1! = STMT. Value1, update of TABLE1. VALUE1 = STMT. Value1, otherwise nothing to do.

    Why are they not simply your needs ' uid and pid that already exist in stmt and table1, if table1.value2 > = 0, then the value table1.value1 = stmt.value1 "? Are you concerned about shooting triggers unnecessarily? It has something to do with null values? The MERGE statement above does exactly what you asked, but, depending on your needs, something simpler and more efficient could do it as well.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

    Published by: Frank Kulash, June 6, 2012 14:51

  • How to hide and reveal content under certain conditions?

    With the help of Acrobat X Pro.

    I have a load of text on a form I want to obfuscate in certain circumstances and to reveal to others.

    I tried to use a text box and put a script in the custom format field to switch between white and transparent fill colors, but it does not work reliably.

    In the meantime, I have a hack with a gazillion overlapping of checkboxes... but there must be a better way.  I can't change the underlying text for various reasons.

    Thanks in advance for any help.

    You can use several read-only buttons that all have the same name and can show/hide them all with a single statement by controlling their visibility:

    getField("cover").display = bYourVar? Display.visible: display.hidden;

    Where the "cover" is the name of the buttons and the bYourVar is a variable which is true when you want that text to be hidden and false when you want to the text to display.

    You can show/hide text by placing it on a separate layer (BCG) and control the visibility of the layer via JavaScript, but setting this up is not possible in this case, given your current constraints on editing.

  • Is it possible to be rolled up under certain conditions to a SQL script file?

    Hi guys,.
    Happy Monday to you all. I have a scenario where I'm queue of 2 files in the same SQL program. Here's what it looks like. Would it not be possible to only of coil for test1 - & p_job_id... SH if & p_file_num = 1 & test2 - p_job_id... SH if & p_file_num = 2?
    define p_user_id = &1
    define p_job_id = &2
    define p_file_num = &3
    
    spool test1-&p_job_id..sh
    
    select
    'module_id=''TEST001C1''
    from job_parameter b, job_parameter a
    where a.job_id = &2
    and a.module_id = 'TEST001'
    and b.job_id = a.job_id
    and b.module_id = a.module_id
    and &p_file_num = 1
    /
    
    select 'exit 0'
    from dual
    where &p_file_num = 1
    /
    
    spool off
    
    
    spool test2-&p_job_id..sh
    
    select
    'module_id=''TEST001C2''
    from job_parameter b, job_parameter a
    where a.job_id = &2
    and a.module_id = 'TEST001'
    and b.job_id = a.job_id
    and b.module_id = a.module_id
    and &p_file_num = 2
    /
    
    select 'exit 0'
    from dual
    where &p_file_num = 2
    /
    
    spool off
    Published by: Raj404261 on June 29, 2009 09:47

    Hello

    Raj404261 wrote:
    Hi Frank,.
    Thanks for getting back to me. You were right about the "set." Regarding:

    spool test&p_file_num-&p_job_id..sh
    

    Do the above however would always generate two files I think. I should have mentioned that I'm passing p_file_num from a shell script which is initialized to 1 or 2 based on an if condition.

    In layman terms, I want to only generate test1 test2 and if p_file_num = 1 if p_file_num = 2. Does that make more sense?

    Exactly what did the SPOOL command above. If you seem to be getting different results, make sure that you delete all existing files with the same names before testing.
    If there isn't that one order of the COIL (excluding SPOOL OFF, naturally), while a single file will be opened. Do not close the file until you are finished.

    Or you can consider having two secondary scripts, called my_file_1.sql and my_file_2.sql, each opens one of the SPOOL files and manages one of the queries.
    In your main script, call one or the other saying:

    @my_file_&p_file_num..sql
    

    Published by: Frank Kulash, June 29, 2009 10:35

Maybe you are looking for

  • Sirius Radio app?

    In the Guide of the supplied functions packed with the Pre, there are the Sirius logo among other companies like Weather Channel, ABC mobile, CNN mobile, etc.  I have the Sprint TV app you're looking for Sirius and found nothing.  Am I missing someth

  • T23 wireless card

    Hi all I will receive my new (old) T23 on ebay next week, but the laptop did not have built-in antennas or a PCI Wireless originally. Because I don't want to upgrade additional antennas (which do not almost as well as those with built in ones), I use

  • system hangs when you sit online game

    my computer crash after going on the site of games pogo tigerwoods online ect.it visit it tell me to download the Shockwave already play.that install. It will not start back upward for at least 10 minutes when crash or IE7 stop answer on game tigerwo

  • My lexmark printer does not print.

    I CAN'T GET MY PRINTER TO PRINT THINGS ON THE COMPUTER, BUT IT WORKS FOR EVERYTHING ELSE. I GOT THE PRINTER AND ALL OF THE LEXMARKS SAID TO DO, BUT IT STILL DOES NOT WORK.

  • How to clear the store persistent on the handheld for my application

    Hey. Final tests and I want to erase the persistent store info my app wrote a previous installation. When I download, install a new version of my application, it does not erase the persistent store. How do this manually on BB, TKS. J