MAX function behaving strange...

I've been researching this for a little bit this morning, and I'm not finding a solution in searching.
I have a simple problem that I'm sure is an easy fix that I'm overlooking.
I have a small piece of code where I am trying to return some information out of one table, I want the MAX COMMENT_DATE, and I want to display a few other fields out of that table. When I add in the COMMENT_USER_ID field it seems to ignore the MAX(COMMENT_DATE) function. The results contain duplicate ACCTNUM with different COMMENT_DATEs.
When I remove the COMMENT_USER_ID from the select statement/group by the MAX function works correctly.
What am I missing? Thanks for looking...
1)
SELECT ACCTNUM, MAX(COMMENT_DATE), COMMENT_CODE, COMMENT_USER_ID
FROM COMMENTS_TABLE
WHERE COMMENT_CODE IN ('NEWCOMMENT')
GROUP BY ACCTNUM, COMMENT_CODE, COMMENT_USER_ID
This first query will return more than one COMMENT_DATE
2)
SELECT ACCTNUM, MAX(COMMENT_DATE), COMMENT_CODE
FROM COMMENTS_TABLE
WHERE COMMENT_CODE IN ('NEWCOMMENT')
GROUP BY ACCTNUM, COMMENT_CODE
This second query returns only the MAX COMMENT_DATE

Welcome to the forum!
The question is: which COMMENT_USER_ID do you want to be displayed along with the max(COMMENT_DATE)?
SELECT ACCTNUM, MAX(COMMENT_DATE)
, COMMENT_CODE
, max(COMMENT_USER_ID) keep (dense_rank last order by COMMENT_DATE)
FROM COMMENTS_TABLE
WHERE COMMENT_CODE IN ('NEWCOMMENT')
GROUP BY ACCTNUM, COMMENT_CODEbye
TPD

Similar Messages

  • IPhone shuffle function behaving strange

    Hi
    I noticed some trange behaviour using shuffle on the iPhone.
    Firstly, when I select all songs in my library and select shuffle, it always seems to shuffle them in the same order. It does not appear to be random. It's at the point now where I know which song is coming up next even when shuffling all songs in my library.
    Secondly, for some songs in my library I have more than one version of the same song. One might be the original, one unplugged, one live, etc. When using shuffle it sometimes play all versions of the same song one after the other in a row.
    Has anyone experienced these problems?
    Thanks

    Shuffle will always work more or less as you describe. Best way to get a random mix (and this is true even in iTunes) is to use a smart playlist.
    Actually, you want to use two of them. The first contains your selection criteria (could be as simple as "Is Music" which will get all music from your collection, but could also be as sophisticated as "not played in the last week and genre is Christmas and rating is 4 star or greater").
    Now create one more smart playlist and this list is just "playlist is " and then the first list. Then choose a certain number of songs (I like 500 because it's usually more than enough) and choose "select at random".
    I promise you this will give you a truly random list and, if you use the criteria that get updated on the fly (like using last played) it will continually change so there is no danger you will ever hear the same song twice, or even that same day (or week, or month :>)

  • MAX behaving strangely...

    I'm trying to do what at first I thought would be a very simple query:
    I am extracting a list of course completions, and need to join to an 'order' and 'order_items' tables (think shopping cart - one order record relates to many order_items records) to find the order date to include in the extract. In the course completion table I have a student ID and product ID. The 'order' table contains the student ID, and the 'order_items' table contains the product ID and order ID. As a student can have multiple orders, I need to make sure I have the correct order and order_item records for the current completion record.
    So, the simple query would be:
    select ord.order_date c.title, c.end_date, c.score, s.name
    from orders ord, course_completions c, students s
    where s.id = c.student_id
    and ord.id in
    (select id from orders where student_id = c.student_id
    and order_id in (select order_id from order_items where product_id = c.product_id));
    However, this doesn't work, as a student might have mulitple orders for the same product (don't ask me why - I think it's bad data, but I have to accomodate for it) - the subquery can return multiple rows, so I am getting duplicate course completion returns with different order dates. I need to filter the subquery, so only the latest order is returned. I have tried using MAX in the subquery:
    (select MAX(id) from orders where student_id = c.student_id
    and order_id in (select order_id from order_items where product_id = c.product_id));
    but this doesn't seem to return the correct number of rows - with my data I should get 11 rows - using the MAX I only get 4.
    Any ideas anyone?
    Thanks in advance
    Darwin LeMay

    Well you could try the following.....
    I added
    * EXISTS for Order_Items - should be quicker.
    * GROUP BY Student_id, this will allow your MAX function to work.
    * Changed the "ORD.Id IN" to "ORD.Id =" since the subquery only returns one row.
    SELECT  ORD.Order_Date
        ,   C.Title
        ,   C.End_Date
        ,   C.Score
        ,   S.Name
    FROM    ORDERS              ORD
        ,   COURSE_COMPLETIONS  C
        ,   STUDENTS            S
    WHERE   S.Id         = C.Student_Id
            -- We only want one order per student, we use equals here.
    AND     ORD.Id       =
                -- Orders per Student per Product.
                SELECT  MAX ( O.Id )
                FROM    ORDERS   O
                WHERE   O.Student_Id = C.Student_Id
                AND     EXISTS
                        (   SELECT  1
                            FROM    ORDER_ITEMS     I
                            WHERE   I.Product_Id = C.Product_Id
                            AND     I.Order_Id   = O.Order_Id
                GROUP BY O.Student_Id
    ;Thanks for your time,
    Eric Kamradt

  • Metronome behaving strangely

    When I press the record button in GB 3.0.4 The level meter displays a pulsing level, but I hear no sound for the metronome until I depress a key on my MIDI keyboard. This remains true whether I have it set to "Count In" or not. Another curious problem is that if I set the metronome to play during both Playback and Recording, I don't hear it during playback, until it reaches a region. For example, if I start playing from m. 1 but no instruments enter until m. 2, I don't hear the click start until after the instruments enter.
    Anyone else having this problem? Any ideas what might be causing it?
    Thanks,
    Michael

    Hangtime, thanks for your help, but the issue isn't the volume of the metronome. Normal GB functionality is that if you have Metronome selected to be "on," then when you click on the Record button you immediately hear the metronome, as well as see the click registering on the meter. I don't hear it, even though it is registering on the meter, until I depress a key on my MIDI keyboard. Then I hear it just fine. I've been working with this software since version 1 came out, and I've never had this problem before. I also have Sibelius, Logic, and Reason, so I am wondering if I may have unknowingly tweaked some setting that is making MIDI in GB behave strangely.

  • Why is my MacBook display behaving strangely?

    I am using an alumin(i)um MacBook (13", late 2008 model with multi-function glass trackpad). In the past couple of weeks, the display has started to behave strangely. The screen seems to freeze (meaning any mouse movements or keystrokes do not display), and then the screen begins to fade to grey. It seems to be resolved by tilting the display until the MacBook "wakes". There has also been some occasional flickering of the display, although far less frequent. Could someone help me with this? Is it something like a loose connection, and, if so, how should I deal with it? (The MacBook is now out of warranty, so my next step would be my local Apple store). Thanks in advance!

    Same thing happening to me - began about four weeks ago, two weeks after warranty expired. Has gotten to the point where it's difficult to use the computer - don't get through composing an e-mail before it starts to fade - now know that even though computer display is frozen, the keystrokes are still getting through, so be careful what keys you press trying to get it to pay attention!
    I believe it's going to turn out to be a connection problem between the computer and the display in the hinge area. I found out yesterday that as it freezes, and I start to pick it up off my lap and put it aside, if I pick it up with my left hand near the lower left of the keyboard and my right hand behind the display, down low near then hinge, and pulling slightly towards me, this fixes it (for a while), and this is (for me) the most reliable way to wake it back up. I've seen references elsewhere to this being a simple problem where a connection is maintained with a black foam pad to provide pressure to the connection. I think the foam must degrade or lose resiliency (apparently at 12.5 months from purchase!) and there may be a simple solution available. When I figure it out for this particular model, I'll post my conclusions.

  • How to Avoid Errors in Max Function When Data Contains Blank Cells

    I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
    I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
    So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
    Thanks,
    Nic

    I don't see a problem with "blank" (null string) cells mixed with duration cells.  MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
    A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"?

  • MAX function

    Hi Everyone,
    Am aware of the following flavors of MAX function
    1) choose MAX from the folders/fields list (selected items tab)
    2) create calculation using: MAX keep dense
    3) create calculation using: MAX analytic function
    questions, pls:
    ===========
    a) with MAX regular, MAX keep dense, MAX - analytic function
    is it necessary to sort it using tools/sort - choose fields to sort by?
    or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing
    does MAX keep dense calculation happen during detail row processing?
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
    tx for your ideas and assistance, sandra

    Hi,
    a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
    Rod West

  • Just done a fresh install of Snow Leopard with all updates,iMac 5.1 behaves strange, sometimes I start Google Chrome and look at youtube videos the computer freezes and shuts down immediately, I believe its  related to overheating ?

    Just done a replacement of the pata DVD drive (its new and is working ok),  and a fresh clean  install of Snow Leopard with all updates, iMac 5.1 behaves strange, sometimes I start Google Chrome and look at youtube videos the computer freezes and shuts down immediately,
    I believe its  related to overheating ?
    iStat Pro shows GPU diode temp at 66 C, CPU at 48 C,  Fan rpms is around 1000
    Any ideas somebody ?
    The hard disk has been previously checked with state of the art techniques that have confirmed that the hard disk drive is in perfect condition.

    1.5-3 minute boot up as opposed to 15-20 seconds
    And
    why it takes a long time to load a lot of things.
    I have restored this
    from a time machine partition.
    TimeMachine is only a backup and restore, it won't fix issues in software and according to your information, doesn't even optimize the restore for best performance on boot hard drives.
    What you need to do to regain your speed is to understand how your machine works
    Why is my computer slow?
    Fix any and all issues in software following this list of fixes
    ..Step by Step to fix your Mac
    Then follow this defrag method I've outlined
    How to safely defrag a Mac's hard drive
    Most commonly used backup methods
    There shouldn't be need to reinstall OS X fresh unless your having file structure issues which if they are should appear when in the Steps, which then a zero erase and install will cure as well as any bad sector issues, the defrag step wouldn't be necessarry on a freshly installed system obviously as the files are written all together, not in portions all over the drive.
    Hope this assists.

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Regarding MAX() function

    Hi,
    I am having table A. I have few records in the table A. Database version : 9.2
    ID name deleted
    2 XYZ N
    3 ABD N
    4 GJK N
    5 GJK N
    6 HGY N
    7 YJG N
    8 PIN N
    9 BMF N
    10 OLG N
    I used the following query...
    SELECT MAX(ID) FROM A WHERE DELETED='N';
    It was worked fine until now....
    Now i used the same query...
    But the result is
    MAX(ID)
    9
    Please help me... What is the reason?
    I want the correct result...
    Thanks in advance....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Kamran Agayev A. wrote:
    Yes you can use TO_NUMBER inside MAX function and it will not give any error in the futureHave you tested it?
    SQL> create table a (id,name,deleted)
      2  as
      3  select '2', 'XYZ', 'N' from dual union all
      4  select '3', 'ABD', 'N' from dual union all
      5  select '4', 'GJK', 'N' from dual union all
      6  select '5', 'GJK', 'N' from dual union all
      7  select '6', 'HGY', 'N' from dual union all
      8  select '7', 'YJG', 'N' from dual union all
      9  select '8', 'PIN', 'N' from dual union all
    10  select '9', 'BMF', 'N' from dual union all
    11  select '10', 'OLG', 'N' from dual
    12  /
    Tabel is aangemaakt.
    SQL> select max(id)
      2    from a
      3   where deleted = 'N'
      4  /
    MA
    9
    1 rij is geselecteerd.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
                        MAX(TO_NUMBER(ID))
                                        10
    1 rij is geselecteerd.
    SQL> insert into a values ('2A', 'ABC', 'N')
      2  /
    1 rij is aangemaakt.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
    select max(to_number(id))
    FOUT in regel 1:
    .ORA-01722: invalid numberRegards,
    Rob.

  • Use of MAX function

    Hi,
    I am using parent-child hierarchy and in my reports I want to show Max(hierarchy_level). When I use the function MAX directly in the report it works fine in every way. But I want to have this kind of column in the BI Server presentation catalog so the user does not need to add MAX in Analysis/Answers (this is 11g). Normally this would imply a Max(hierarchy_level) as a logical function, but in the BI Server it is not allowed with MAX function in the logical function so it does not work.
    The hierarchy level is just a column from a dimension table and creating it as a fact column is not a very good solution. I also tried to solve this in many different ways, but only the MAX funtion in Analysis/Answers allways give the correct result. Used in combination with other dimensions etc. I want the exact same behaviour as I get when using MAX in analysis.
    Any good ideas to solve this? Is there another function in the BI Server that works the same way as MAX ?

    Very often, about a primary key, see for example our italian accounting application (our VAT invoices:fatture IVA) ), where the holes might be a problem.
    Yes Rosario, of course I know that, and that's why I said "in this scenario" : if primary key is the only purpose, I don't think holes could be a problem.
    Buona giornata anche a te.

  • Has anyone ever encountered layer blend modes behaving strangely?

    I use photoshop quite a bit for retouching and photo compositing. Tonight I encountered a strange problem. I was trying to create a vintage look on a photo and had a number of adjustment layers including a curves, levels, color fill and there were also a few texture/noise layers all set to varying opacities. Near the top of all this I had a vignette layer that was black around the edges and white in the center set to blend mode of multiply. Well, when I was clicking on and off I realize that that vignette layer was definitely lightening the center part of the overall image quite a bit (the part that is white on the vignette layer), almost like a screen. So I flipped the vignette layer through different opacity modes and saw that there was no change in its behavior, every mode was screening the white, even darker color and multiply. I thought maybe it was interacting in a weird way with one of the other layers so I turned all the others off except the back ground-- still no change. Then I dropped the layer down one at time until it was below the background. When I started to move it up again, it was behaving normally for a moment until I moved it up a couple levels in the stacking order and then it went back to the screen behavior. Anyway I shuffled it around a bit but there was no consitency to when it would display the correct opacity and when it wouldn't, so it did not seem to be an interaction with any specific layer. I don't know, but I can't really think of any case where white set to multiply should produce a lighter result even if it were interacting with another opacity. In any case it does seem to me that there is something going on with the overall computation of opacities. I tried creating a new black and white layer and it was also doing the same thing, behaving strange and not displaying the correct opacity.
    I'm tired, so I'm going to bed. I'm going to shut off the computer and hope this goes away when I reboot, but if it does not, does this sound familiar to anyone? I'm not a regular visitor to this forum, but I thought I'd put it out there in case anyone else has experienced anything like this. I've only got 5 gigs of ram on this computer and I've been working away for a while... maybe photoshop just couldn't keep up(?) I'm using Photoshop CS5, RGB Adobe 1998 colorspace.  I've never had anything like this happen in the last 11 years I've been using photoshop. Hmmm.... hope I don't have to reinstall or call support or worse. fingers crossed.

    Nevermind. It is still having the problem. I have to think that this file is just corrupt somehow because I just opened another file and can't seem to cause the same problem. Basically, I can fill a layer with white, put it to a blend mode of multiply or darker color and it will block out everything of the image below, ie totally opaque. The opaqueness varies depending on the if there are other layers also on blend modes, but it does not seem to correspond to normal blend mode interaction. If I put it right on top of a regular layer with an image on it, it totally blocks it out on a blend mode of multiply... weird. I am going to scrap this file and see if the problem recurs in other files. My 2006 Mac Pro is getting some years on it and has been running pretty slow. I'm not a hardware expert but I've done everything I know how to do to maintain it. Was thinking of upping the ram to see if I can hold out a bit longer before I upgrade the computer. Wouldn't surprise me if this problem is related to the computer.

  • Use of MAX function in Query Designer

    Dear all,
    i want to create a report that gives ONE line per period that holds the MAX of several lines per period. So NO addition of the KF but just one line item.
    I tried to use the MAX function and/or MAX drop-down boxes via properties on KF,
    but they all provide the wrong result (mostly the MAX after summaction of the KF).
    Any ideas ??
    Greetz,
    Herman

    Hi Herman
        Please check the KF infoobject property which might have been set to Summation.  You need to change the property of the KF to MAX if you wish to have MAX value. 
        Hope this might be helpful to you
    Thanks
    Kishore Kusupati

  • My Macbook Air behaves strangely with my USB devices.

    Hello! My Macbook Air behaves strangely with my USB devices. They appear in the Finder but the icon then quickly disappears, as if the device has never been connected. Sometimes the devices work fine, however. Could you please help me identify the problem?

    USB draws power from the MBA, and MBA will shut them down if too much is taken.  Try a self-powered (not USB-powered) hub, to see if the AIr acts better.  Costs about $25 at BestBuy.
    May not tbe the final solution, but no a bad idea anyway.

  • How to use MAX function in SSAS MDX Query

    I want to run this Query with MAX Condition on LAST_DATA_UPDATE Column .

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • GIF decoding

    This works on WinXP but not Linux. Why? It takes the first frame of an animated gif and writes a thumbnail.             GifDecoder d = new GifDecoder();                 try {                 fis = new FileInputStream(file);                          

  • Selection String Empty when Refresh Report

    I'm using CR2008 in VS 2008 (WinForms not Web). This seems like a fairly easy thing to do (was in VB6/CR8.5). My program provides a list of reports via the FileDialog, grabs the report name, loads the report document with the report, then the viewer

  • How to force topics to be ranked higher in Search?

    I am using RH9. I have read the articles about how Search results are ranked: In order, it is based on the search word appearing in: The topic title (as in Topic Properties and not to be confused with the Topic Heading) The topic keywords (Increasing

  • Cant open itunes when ipod connected

    I cant open i tunes when my ipod is connected. as soon as i disconnect it itunes comes up. if i connect my ipod with itunes already running it stops working. im really starting to loose my patience help!

  • Why does the iPod 4g freeze every 5 min ?

    Why does the iPod 4g freeze every 5 min ? This is really annoying. I will choose Samsung next time if apple continue like this. Samsung is much better. I'm on iOS 6.1.5 (last update). Does apple do a bad a updat to force people de buy a new idevice.