Aggregate function not working correctly

I have this data in a table
SZSTCLA_PIDM     SZSTCLA_TERM_CODE       SZSTCLA_TERM_CODE_MATRIC     SZSTCLA_TOTAL_CREDITS
82724                        201010                                               201010                      4.50
82724                       201020                                              201010                      4.50
82724                       201110                                              201010                      4.50
82724                       201120                                              201010                      4.00
82724                       201210                                              201010                      0.00
82724                      201220                                              201010                     0.00
82724                      201310                                              201010                     3.00 when I run this query
SELECT szstcla_pidm,
                  szstcla_term_code,
                  SUM (
                     SZSTCLA_TOTAL_CREDITS)
                  OVER (PARTITION BY szstcla_pidm
                        ORDER BY szstcla_term_code
                        ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING)
                     AS aggr_hours,
                  szstcla_term_code AS szstcla_term_code_2
             FROM szstcla
            WHERE                                  ---szstcla_pidm    =  82085
                 szstcla_term_code >= szstcla_term_code_matric
                 AND SZSTCLA_TOTAL_CREDITS > 0
         ORDER BY szstcla_pidm I ended with
82724     201010          201010
82724     201020     4.5     201020
82724     201110     9     201110
82724     201120     13.5     201120
82724     201310     17.5     201310 It is not counting
82724                      201310                                              201010                     3.00 I should ended with
82724     201010          201010
82724     201020     4.5     201020
82724     201110     9     201110
82724     201120     13.5     201120
82724     201310     17.5     201310
82724     201320     20.5     201320

Chris and Karthic have it right, there is no 201320 term code so you won't get a record for that term until one is inserted in your table and your sums are based on the window you specified.
What I'm wondering though is if you want to partition by the SZSTCLA_TERM_CODE_MATRIC column as well as SZSTCLA_PIDM. In your where clause you are limiting the rows to those where SZSTCLA_TERM_CODE is >= to SZSTCLA_TERM_CODE_MATRIC, but are you likely to have rows with SZSTCLA_TERM_CODE < SZSTCLA_TERM_CODE_MATRIC? There weren't any in your sample data, but I would expect that you may have multiple matriculation terms for a given PIDM. If you want to restart the calculation every time the student matriculates, you'll want to partition by that matriculation term.
Have a look:
with szstcla as (
  select 82724 SZSTCLA_PIDM, '201010' SZSTCLA_TERM_CODE, '201010' SZSTCLA_TERM_CODE_MATRIC
         , 4.50 SZSTCLA_TOTAL_CREDITS from dual union all
  select 82724, '201020', '201010', 4.50 from dual union all
  select 82724, '201110', '201010', 4.50 from dual union all
  select 82724, '201120', '201120', 4.00 from dual union all
  select 82724, '201210', '201120', 0.00 from dual union all
  select 82724, '201220', '201120', 0.00 from dual union all
  select 82724, '201310', '201120', 3.00 from dual
select szstcla_pidm PIDM
     , szstcla_term_code_matric TC_MATRIC
     , szstcla_term_code TERM_CODE
     , sum (szstcla_total_credits)
       over (partition by szstcla_pidm
             order by szstcla_term_code
             rows between unbounded preceding and 1 preceding) agg_hours
     , sum (szstcla_total_credits)
       over (partition by szstcla_pidm
             order by szstcla_term_code
             rows between unbounded preceding and current row) agg_hours2
     , sum (szstcla_total_credits)
       over (partition by szstcla_pidm, szstcla_term_code_matric
             order by szstcla_term_code
             rows between unbounded preceding and 1 preceding) agg_hours3
     , sum (szstcla_total_credits)
       over (partition by szstcla_pidm, szstcla_term_code_matric
             order by szstcla_term_code
             rows between unbounded preceding and current row) agg_hours4
  from szstcla
  where szstcla_term_code >= szstcla_term_code_matric
    AND SZSTCLA_TOTAL_CREDITS > 0
  order by szstcla_pidm, szstcla_term_code;
PIDM     TC_MATRIC     TERM_CODE     AGG_HOURS     AGG_HOURS2     AGG_HOURS3     AGG_HOURS4
82724     201010          201010                    4.5                    4.5
82724     201010          201020          4.5          9          4.5          9
82724     201010          201110          9          13.5          9          13.5
82724     201120          201120          13.5          17.5                    4
82724     201120          201310          17.5          20.5          4          7I modified your original sample data to include a change in matriculation term codes part way through the data. The last AGG_HOURS and AGG_HOURS3 share the same windowing clause as your original query, AGG_HOURS2 and AGG_HOURS4 share the windowing clause proposed by Chris, and AGG_HOURS3 and AGG_HOURS4 add the additional partition on the matriculation term code.

Similar Messages

  • Brush function not working correctly PS Elements 11 for Mac

    The brush is not working correctly in that I cannot drag the brush.  It allows only spot healing, not dragging the brush.  Didn't use to have this problem.  Now do.  Not sure what has changed.  Thank you!

    Is this happening after upgrading to Yosemite?
    If yes, please see:
    Photoshop Elements doesn't respond when you use editing tools in Mac OS X 10.10
    Thanks,
    Anwesha

  • EJB 3.0: EJBQL aggregate functions not working properly

    Hi!
    We are experiencing problems when using aggregate functions within EJBQL queries. In my case, we have to use max() function to retrieve the max start_date from a specific table. In order to do this, we wrote the following code:
    String strQuery = "select max(o.dt_fim) from Questionario o";
    Query queryTeste = em.createQuery(strQuery);
    List x = queryTeste.getResultList();
    OBS: dt_fim is an Oracle 10g datetime column, with its corresponding entity attribute in Questionario entity class.
    AFAIK, the query above should return only one record (object instance) containing the date value, right? However, it brougth a list of the entity objects, corresponding to all records in the table, as we had just run "select o from Questionario o".
    Examining the server log we can see this behavior:
    [TopLink Fine]:2006.09.12 01:47:55.526--
    ServerSession(7119662)--Connection(7048401)--Thread(Thread[ApplicationServerThread-0,5,RequestThreadGroup])
    --SELECT ID_QUEST, DT_INICIO, DT_FIM, DS_QUEST, DT_CRIACAO, TP_QUEST, NM_QUEST, COD_SEGMENTO, ID_GRUPO FROM TBBOP_QUEST
    Are anyone experiencing this issue?
    Is there any workaround?
    Any help would be much appreciated, since we need to deploy the application for user testing asap.
    Thanks in advance.
    Best regards,
    Gustavo
    PS: We are using JDeveloper 10.1.3.0.4(SU4)
    Message was edited by:
    Gustavo Lopes Sobral

    The 10.1.3.0 versions of JDeveloper contain our early preview of EJB 3.0 JPA functionality. One limitation is that the query language is not complete (released before the spec was finalized).
    You can use TopLink Essentials (JPA Reference implementation) whihc contains a complete compliant implementation of the final specification.
    http://otn.oracle.com/jpa
    The 10.1.3.1 JDeveloper preview ships with TopLink Essentials.
    Doug

  • XQuery translate() function not working correctly?

    The following XQuery fragment
    return
    xf:translate($product/@description, "&#174", "®")
    where
    $product/@description
    contains
    Complete Choice&#174 Plan
    returns
    Colete Choice® Pln
    not, as expected
    Complete Choice® Plan

    967660 wrote:
    Hi,
    Another quick question if people don't mind. Bit confused about the trunc date function. I'm following the sql fundamentals exam guide and using their examples:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy hh24:mi')) day from dual;
    this returns the 2nd of june, as it should, because, as far as i'm aware, leaving the optional variable out defaults the precision to 'day'. but when i explicitly add the variable 'day', as the guide has done with 'week' 'month' and 'year' in the following examples (so i assume this format is correct rather than dd/mon/yyyy), something goes wrong:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy' hh24:mi'), 'day') day from dual;
    this returns the 31st of may. which is incorrect.
    however replacing 'day' with 'dd' provides the correct answer of the 2nd again.
    this isn't a major issue, it just bothers me that the guide seems (again) to be mistaken, something that is rapidly becoming a trend in their examples. i'd also quite like to know why this is happening, as it will help improve my understanding of sql in general - perhaps there is some sort of default to allow the correct use of the variable 'day' i'm overlooking and that the guide hasn't made clear.
    btw, i'm working in sqlplus - although developer has some odd results too.
    thanks alot,
    nick'day' doesn't trunc to the beginning of the day. It truncates to the first day of the week: in your case 31st May.
    'ddd' truncates to the beginning of the day.
    So, leaving the second parameter out defaults to 'ddd' not 'day'.

  • Trunc date function not working correctly

    Hi,
    Another quick question if people don't mind. Bit confused about the trunc date function. I'm following the sql fundamentals exam guide and using their examples:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy hh24:mi')) day from dual;
    this returns the 2nd of june, as it should, because, as far as i'm aware, leaving the optional variable out defaults the precision to 'day'. but when i explicitly add the variable 'day', as the guide has done with 'week' 'month' and 'year' in the following examples (so i assume this format is correct rather than dd/mon/yyyy), something goes wrong:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy' hh24:mi'), 'day') day from dual;
    this returns the 31st of may. which is incorrect.
    however replacing 'day' with 'dd' provides the correct answer of the 2nd again.
    this isn't a major issue, it just bothers me that the guide seems (again) to be mistaken, something that is rapidly becoming a trend in their examples. i'd also quite like to know why this is happening, as it will help improve my understanding of sql in general - perhaps there is some sort of default to allow the correct use of the variable 'day' i'm overlooking and that the guide hasn't made clear.
    btw, i'm working in sqlplus - although developer has some odd results too.
    thanks alot,
    nick

    967660 wrote:
    Hi,
    Another quick question if people don't mind. Bit confused about the trunc date function. I'm following the sql fundamentals exam guide and using their examples:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy hh24:mi')) day from dual;
    this returns the 2nd of june, as it should, because, as far as i'm aware, leaving the optional variable out defaults the precision to 'day'. but when i explicitly add the variable 'day', as the guide has done with 'week' 'month' and 'year' in the following examples (so i assume this format is correct rather than dd/mon/yyyy), something goes wrong:
    select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy' hh24:mi'), 'day') day from dual;
    this returns the 31st of may. which is incorrect.
    however replacing 'day' with 'dd' provides the correct answer of the 2nd again.
    this isn't a major issue, it just bothers me that the guide seems (again) to be mistaken, something that is rapidly becoming a trend in their examples. i'd also quite like to know why this is happening, as it will help improve my understanding of sql in general - perhaps there is some sort of default to allow the correct use of the variable 'day' i'm overlooking and that the guide hasn't made clear.
    btw, i'm working in sqlplus - although developer has some odd results too.
    thanks alot,
    nick'day' doesn't trunc to the beginning of the day. It truncates to the first day of the week: in your case 31st May.
    'ddd' truncates to the beginning of the day.
    So, leaving the second parameter out defaults to 'ddd' not 'day'.

  • Mod function not working correctly

    I wrote a code to decimal to binary number system, this code works properly for 5 but show wrong result on 47. I tried lots of times but not getting solution.When "23.5 mod 2" calculated I
    got the remainder 0 which is worng it should be 1.
    Private Function convertor_bin_and_octal(num1 As Double, system As Byte) As String
    Dim Exponent As Double, mantes As Double, num As Double, h As Byte
    Dim b As String
    Dim a As String
    If IsNumeric(num1) = True Then
    num = Int(num1)
    Exponent = num1
    While num >= system
    Refresh
    h = num Mod system
    a = a & Str(h)
    num = num / system
    Wend
    a = a & Int(num)
    a = StrReverse(a)
    num = num1
    ma = Exponent - Int(num)
    If ma <> 0 Then
    While ma <> 0
    ma = ma * system
    b = b + Str(Int(ma))
    ma = ma - Int(ma)
    Wend
    a = a & "." & b
    End If
    convertor_bin_and_octal = a
    Else
    Label2.Caption = "Please enter the numeric value only"
    Text1 = ""
    Text1.SetFocus
    End If

    Please move your post to VB forum here:
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=vbgeneral
    Fouad Roumieh

  • Playlist function not working correctly

    I have an Ipod nano 4th generation, it works fine in every way it is supposed to except when it come to the playlist function. When ever a song is selected from a list of songs or an artist/album list containing 10+ or so songs it does not add the selected son go to the on the go playlist on the ipod. Instead it adds a completely random song from the list with no logic to the song it picks. Does anyone else have this problem or know how to solve it? I have sent one Ipod away to be fixed but the replacement appears to have the same problem. Is this an issue with all 4th generation nanos or am I just rather unfortunate? if it is a recurring issue have apple acknowledged it/done anything about it?

    Because you have uploaded the files with the iWeb FTP, the folder of files created by iWeb - southcoasttv - has been uploaded along with the index.html file. Therefore the URL has the folder name in it and this is normal.
    You can change it if you want but you need to use an FTP application to upload the files rather than the whole folder....
    http://www.iwebformusicians.com/WebMusic/URLs-Favicons.html

  • DW logout function not working correctly

    I have CS4 on Vista ultimate.  I am using WAMP for testing.
    In DW, I clicked on the menus to make a logout page.  To test it I logged in as a user in one window(FF) and opened another one and logged in as a different user... When I hit the logout button on one, it logged out both users....
    How can this be that everyone gets logged out by one?  I have used dw's login and logout functionality and have not changed either...
    any ideas?

    You say that session objects are shared between all browser window/tab instances.... Those are 2 different things... tabs are in windows...Open a new window and it should be unrelated to the others....
    isnt each session id for each window unique?
    I have 2 different FF windows open, each logged in as a different user, log out one, the other is logged out as well....
    But, since your post I tested with IE and FF and then it works how its supposed to, only one is logged out...
    I understand how sessions work but thought that each window had it own unique session id, especially for different users.... I guess thats only true on two DIFFERENT browser windows... weird....
    seems like it should not be that way, but it is... so oh well, I guess thats not a real problem, just seemed like one.  Thanks.

  • A PDF function not working correctly in Pro and Reader

    Here is more information from the field staff who informed me of the issue:
    As far as adding pictures to Live Cycle form.
    When field personnel entering the inspection data into the form, if it opens in Reader, they cannot add a photo by clicking on the “paperclip” in the lower left of the form.   The “Add” button is not there.  The can add an image in the field in the form, but I cannot get it out of the form to put into the database…you cannot manipulate the image at all once it is in the field area of the form.  No right click to copy, cut or delete.
    In Adobe Acrobat Pro 9, you can click on the paperclip, add an image file, BUT cannot right click on file to copy elsewhere..which is what I would want to see us be able to do.  I have to save the file as something else, then put it in my database…I don’t want to have to save it as something else due to our numbering system that we are using to file these…A HUGE HEADACHE..
    IF I try to add an image directly to the field in the form, once it is there, you cannot right click to delete it (copy it, cut it)..you cannot get rid of it…only “replace” it with another image….not exactly user friendly if you attach a photo by mistake…
    those are the issues I have with the live cycle form.  we are working on trying to get the information dumped directly into a database, if there are instructions on doing that I would like to have those.  It would save me a lot of time and effort.

    Is this a LabVIEW or a signal express question?
    (You post in the LabVIEW forum but only mention signal express. There is a dedicated signalexpress forum. If this is a LabVIEW question, please explain in more detail.)
    LabVIEW Champion . Do more with less code and in less time .

  • Search function not working correctly

    I have a problem searching in a specific document. For some reason, the search function only seems to sift through certain fonts, or types of text. The main text is not included in the search, but rather only (for example) the Table of Contents and some "examples" (in a special font) in the text. Everything else is omitted.
    When I copy/paste the main text, it's pasted as a strange code in this fashion, despite the fact that it's quite readable in it's original form:
    äíÉí=áåíÉ=Ü~ê=Ñí
    This is probably the reason why Search can't find terms in the main text, as searchable text looks quite right when copy/pasted. But how can I solve the problem?
    Thanks!
    David

    Did you check under the file Properties to see if the fonts are embedded? If they are not, you can reembed the fonts if you have Acrobat Pro using the Preflight tools.

  • Javascript sort() function not working correctly

    I have an image gallery that automatically loads via a PHP readdir function which populates an array, and then I have a Javascript sort() function which sorts the images in order numerically. In Chrome and Safari, the images display as numbered in the directory. However, in Firefox and Internet Explorer, they display out of order (firefox) and not at all (ie). Here is the code for the php file: <?
    Header("content-type: application/x-javascript");
    function returnimages($dirname=".") {
    $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
    $files = array();
    $curimage=0;
    if($handle = opendir($dirname)) {
    while(false !== ($file = readdir($handle))){
    $file = basename($file,".jpg");
    echo 'myImg['.$curimage.']="'.$file .'";';
    $curimage++;
    closedir($handle);
    return($files);
    echo 'var myImg=new Array();';
    returnimages()
    ?>
    and here is the code for the javascript sort:
    function sortNumber(a,b)
    return a - b;
    myImg.sort(sortNumber);
    // Tell browser the type of file
    myImgEnd = ".jpg";
    var i = 0;
    // Create function to load image
    function loadImg(){
    document.imgSrc.src = myImg[i] + myImgEnd;
    Any ideas as to why Firefox is behaving this way?

    After you check the box to sort on the column, are you making sure to select a sort order for the same column?
    Earl

  • Wireless Function Not Working Correctly

    When I try to print wirelessly, it prints 2-3 pages and then quits printing, often right in the middle of a page, and tells me there was a printing error. When I print through a cable, it works perfectly. The printer is about 13 feet away from the internet router and not plugged into the router.  It is plugged via USB into a desktop computer running Windows 7 32-bit.

    Hi @Musicrafter , and welcome to the HP Forums!
    I see you're experiencing connectivity issues.  I would like to try and help!
    I would recommend performing a power reset.   Disconnect the power cord from the printer and the power outlet, then wait 60 seconds. After 60 seconds, plug the printer back in. Ensure you plug the printer directly to a wall outlet. Make sure to bypass any sort of surge protector or power bar.
    I'd also suggest this document on Wireless printing center Troubleshooting Issues.
    Good luck and please let me know the results of your troubleshooting steps. Thank you for posting on the HP Forums!
    Please click “Accept as Solution " if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the right to say “Thanks" for helping!
    Jamieson
    I work on behalf of HP
    "Remember, I'm pulling for you, we're all in this together!" - Red Green.

  • Aggregate functions not working on SQL Server source datetime2 column

    I can happily replicate data from a SQL Server 2008 R2 source table, datetime2(7) to an Oracle 11g Release 2 target table, TIMESTAMP column:
    I create a new temporary interface, right-click on the datetme2 source column, Add Column to Target Table and the data is replicated into an ORACLE TIMESTAMP.
    But if I change the mapping to MIN(<source column>) or MAX(<source column>) then the interface doesn't fail, but my target table is simply empty.
    I noticed that in my ODI (version 11.1.1) doesn't have datetime2 listed as a Microsoft SQL Server Datatype, so I'm trying to solve the problem by creating and using such a datatype but no joy so far.
    Has anyone got any advice / experience on this?
    Keith H.

    The 10.1.3.0 versions of JDeveloper contain our early preview of EJB 3.0 JPA functionality. One limitation is that the query language is not complete (released before the spec was finalized).
    You can use TopLink Essentials (JPA Reference implementation) whihc contains a complete compliant implementation of the final specification.
    http://otn.oracle.com/jpa
    The 10.1.3.1 JDeveloper preview ships with TopLink Essentials.
    Doug

  • ATP FUNCTIONALITY NOT WORKING CORRECTLY FOR ATO Model

    Guru's,
    Currently I am facing issue in ATP Inquiry to arrive at schedule ship date, we have set up an ATO Model and its low-level parts for multi level ATP, including ATP rules, item attributes, bom attributes, and lead times and ATP check is based on planned output and enabled 24X7 plan.
    When try to perform ATP inquiry either from ASCP/OM responsibility, Instead of showing complete drill down of material constraint at the part level, it "stops" at the model level and shows no availability until the inifinte supply timefence, then unlimited availability after that.
    I was earlier able to view the complete ATP pegging details with ATP dates well within ITF, but however when we re run the plan to include additional SO the above behavior is observed.
    Can some one help me to reslove the issue, as I am not sure what exactly which is triggering this behavior.
    Thanks,

    Thanks for the reply, but this note was not addressing the above stated issue. In this note for matched configuration, they are not able to view pegging else they are able to perform multilevel atp check.
    Can anyone help me to reslove this issue.
    Thanks
    Edited by: user604737 on Jun 18, 2011 4:48 AM
    Edited by: user604737 on Jun 19, 2011 11:50 PM

  • Adobe Prelude CC search function not working correctly?

    Hey guys,
    In need of some help, I am using the "tag" feature in prelude CC, tagging clips with multiple words IE "Day One, Interview, Ben"
    When searching the footage the clips can be seen if I type the words "Day One" or "Ben" however if I type them back to back IE: "Day One Ben" Prelude can't find any footage.
    I really need to be able to search for multiple tags/comments at once. Have tried this in Premiere CC and it works perfectly just Prelude isn't.
    Has anyone else had this problem or can suggest a fix of how to search for multiple tags/comments.
    Thanks,
    Nico

    Hi -
    Prelude currently searches for exact string matches - including punctuation. 
    We are looking into providing a more capable search engine in the future.
    Regards,
    Michael

Maybe you are looking for

  • Two IPAD 2s with same IMEI # - horrible customer support to resolve issue

    A week ago my boyfriend discovered that Verizon had disconnected service to the iPAD 2 I gave him from his account 7 months ago but continued to charge him $11.21 per month for the phone line on a non-existent device.  To date I have spoken with more

  • Inspection Rounds in Work Manager 6.0

    Hi all, We've setup Work Manager 6.0 running on SMP2.3.  One of the functions that I'd like to get working is inspection rounds. We have Configued the standard order type PM01 to be an inspection rounds order in the work order MDO filter INSP_ORDER_T

  • Cannot Create Albums: Clicking on Photo in New Album Changes Photo

    This is really strange. When I import photos from a USB device the import seems to work O.K but if I create a new album when I click on any of the photos in the album, the photo is changed to a different photo from my library. This occurs even if I c

  • Old USB Cable (591-0222) With iPhone 3GS

    Hello, I accidentally charged my iPhone 3GS with an old Apple USB cable (Model# 591-0222), rather than the new MA591G/A USB cable. I think the old Apple USB cable was from a 2nd Generation iPod. It appeared to charge the phone fine. Just curious if I

  • Partner Function text

    Hi BW Gurus, I need to load transaction data to infoobject ship to, Ship to info object is in Sales ods.I need to load the partner function text for this Ship to info object. The logic is: we need to take  the sales doc number from vbak for order typ