Query to pick only first value/day

I have a table with Account, Complaint and Date columns. Each Account can log multiple complaints each day.
Now i need a query to pick only the first complaint in a day from each account. If the same account logged in a complaint next day or any day after i want to show that as well.
Help me with your ideas. Thanks in advance for your help.

Maybe
with
first_complaints as
(select account,
        date
   from (select account,
                date,
                row_number() over (partition by account order by date) rn
           from a_table
  where rn = 1
select account,
       complaint,
       date
  from a_table t
where account in (select account
                     from first_complaints
   and date >= (select date
                  from first_complaints
                 where account = t.account
Regards
Etbin
Message was edited by: Etbin
rereading: If the same account logged in a complaint next day or any day after i want to show that as well.
The query above is just select * from a_table
Now:
if you want to show just the first complaints in a day for any following date, John answered that already (it's just the first_complaints of mine)
if you want to show all the complaints in any following date, you have to exclude all the complaints logged the first day except the first one
select account,
       complaint,
       date
  from (select account,
               complaint,
               date,
               row_number() over (partition by account order by date) rn
          from a_table
       ) t
where date != (select min(date)
                  from a_table
                 where account = t.account
   or rn = 1

Similar Messages

  • Display only first value of the repeated values  in ALV report

    Hi,
    Test Data
    Doc No   Net Val   billing Doc value Qty
    1000      2000.00    567850.00
    1000      2000.00    567850.00
    1000      2000.00    567850.00
    2000      6000.00    767850.00
    In this type of ALV Report in which only the First field value of the repeated value  should be displayed.
    Doc No   Net Val   billing Doc value Qty
    1000      2000.00    567850.00
    2000      6000.00    767850.00
    I can display document value as like expected result in SORT ORDER in LAYOUT but the Quantity value,Net value  which cannot be done in SORT ORDER in LAYOUT.
    Please tell me the suitable solution.

    For a Sales Order there are two Invoice.
    Sales doc     Invoice No    Billed Qty    Net value                     Qtywith  material no
    5000              900             234774.00    456.00000                 65             123
                                             234774.00    456.00000                 25             456
                                             234774.00    456.00000                 35             898
                                             234774.00    456.00000                 20             496
                          901            634774.00    256.00000                 50               746
                                            634774.00    256.00000                 10               456
                                            634774.00    256.00000                 20               545
                                            634774.00    256.00000                 30               869
    I  need to print this billed Qty and Net value  only once in first line and it should not be deleted.
    I need the result like this
    Sales doc     Invoice No    Billed Qty    Net value                     Qtywith          material no
    5000              900             234774.00    456.00000                 65                     123
                                                                                    25                     456
                                                                                    35                     898
                                                                                    20                     496
    5001              901            634774.00    256.00000                 50                       746
                                                                                    10                       456
                                                                                    20                       545
                                                                                    30                       869               
    The same value should not be repeated for Billed Qty and Net Value.
    I can do that for Sales doc in sort order in layout but i couldn't do for Billed qty and Net Value.
    Please  help.

  • Query Panel LOV Selecting first value

    Hi all,
    I created a LOV to use for one of my VOs. I created it as an Input Text with List of Values. I updated the AF Table using this view to use the new list of values and it works correctly. However in the query panel for the table when you try and select a value from the LOV it always chooses the first record in the LOV no matter which one you select. The query panel is implemented as a separate pop-up/dialog for the AF table.
    I'm not sure why it is working fine on the actual table but not working correctly in the query panel.
    Any help is appreciated.
    Thanks
    Jdev 11.1.2.2.0

    Found the solution to this one.. I did not specified which were the key columns in the VOs that I created to reference in the LOV.
    Once I specified the key column in the VO, the LOV returned the correct value in the Query Panel too.

  • JPA named query should return only first result

    Hello,
    I'm quite new to JPA.
    How can I return only the first result of a query? This must happen in the database, not by getSingleResult() from the EntityManager because the table has appr. 15 mio entries.
    Does the JP QL provide this? like the LIMIT keyword in MySQL?
    thanks from germany
    Dirk

    I moved this question to: Forum Home » Java Enterprise & Remote Computing » Enterprise JavaBeans
    Donat

  • Query to select only Y values , if all are Y, say All

    Kinldy provide me the query
    select * from FILTER_User
    CREATE TABLE [dbo].[FILTER_User](
    [UserName] [nvarchar](128) NULL,
    [Is_Member] [char](1) NOT NULL
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Raj', 'Y')
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Ravi', 'Y')
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Kumar', 'Y')
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Gopal', 'Y')
    -- If all the Values in [Is_Member] is Y, display all
    select * from FILTER_User
    Expected Result
    All
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Sridhar', 'N')
    INSERT INTO FILTER_User (UserName, Is_Member) VALUES ('Aravind', 'Y')
    -- If all the Values in [Is_Member] is not Y, display the names which are Is_Member] Y
    select * from FILTER_User
    Expected Result
    Raj
    Ravi
    Kumar
    Gopal
    Aravind
    ShanmugaRaj

    Check this:
    declare @filter_user table(name varchar,Is_Member varchar(10))
    insert @filter_user select 1,'Y'
    insert @filter_user select 2,'Y'
    insert @filter_user select 3,'Y'
    insert @filter_user select 4,'Y'
    declare @sumy int,@sumall int
    select @sumy=sum(case Is_Member when 'Y' then 1 else 0 end) ,@sumall=sum(1)
    from @filter_user
    if(@sumy=@sumall)
    select 'All' as result
    else
    select name as result
    From @filter_user
    where Is_Member='Y'
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Not all selection screen value coming from selection screen only first val

    hi i am doing
    SELECTION-SCREEN BEGIN OF BLOCK gl_ac3 WITH FRAME TITLE text-019.
    SELECT-OPTIONS: gl_acdp1 FOR gv_gldep1.
    SELECTION-SCREEN END OF BLOCK gl_ac3.
    then i am using seelct as below
    SELECT      robukrs
                    rzzhkont
        FROM  zzamd1t INTO TABLE it_amdt
           WHERE ryear = p_gjahr
           AND   robukrs IN so_bukrs
           AND   rzzhkont IN gl_acdp1.
    but the value selected by select statement from internal table is for only first value of gl_acdp1 ie for first account c1 but user is entereng three acts c1 c2 and c3 so fro all data should be selected but for only one it is being selected
    pls sugest

    Hi,
        Is gv_gldep1 & rzzhkontare of same data type.
    Do as below
    SELECTION-SCREEN BEGIN OF BLOCK gl_ac3 WITH FRAME TITLE text-019.
    SELECT-OPTIONS: gl_acdp1 FOR gv_gldep1.
    SELECTION-SCREEN END OF BLOCK gl_ac3.
    INITILIZATION.
    MOVE 'I'      TO  gl_acdp1-sign,
               'EQ'  TO  gl_acdp1-option,
               'C1'   TO  gl_acdp1-low,
       APPEND gl_acdp1.
    MOVE 'I'      TO  gl_acdp1-sign,
               'EQ'  TO  gl_acdp1-option,
               'C2'   TO  gl_acdp1-low,
       APPEND gl_acdp1.
    MOVE 'I'      TO  gl_acdp1-sign,
               'EQ'  TO  gl_acdp1-option,
               'C3'   TO  gl_acdp1-low,
       APPEND gl_acdp1.
    START-OF-SELECTION.
    SELECT robukrs
                 rzzhkont
                               FROM zzamd1t INTO TABLE it_amdt
                               WHERE ryear = p_gjahr
                               AND robukrs IN so_bukrs
                               AND rzzhkont IN gl_acdp1.
    Make sure that ur table zzamd1t has values for C1, C2 and C3.
    Tell us how is ur output with this code.
    Regards,
    Bala Krishna
    Edited by: Bala Krishna on Aug 11, 2008 9:11 PM

  • Show Only First N Rows in SAP Design Studio Chart/Table

    Hi,
    Is it possible to show only first N rows of data in SAP Design Studio Charts/Cross Tab ?
    Eg
    Bex Query Output
    Here If I mention First 2 rows, my chart looks like below
    If I mention First 4 rows, my chart looks like below
    Thanks
    Anil

    Hi Mustafa,
    Thanks for your reply.
    Actually our requirement is, we have one Bex Query where we are using Ranking Function.
    We have 15 customers, and we need to know the ranking based on some calculations.
    Whenever we execute the query with different time periods, the ranking of Customers will vary, for example if I execute query for year 2014, customer 1 can be Rank 1, If I execute for year 2013, Customer 7 can be Rank 1.
    From this Query I need to show only Top 5 Customers in Cross Tab/Chart.
    We tried to put condition on CY Ranking in Bex to show only Top 5, but the result was giving some diff customers and also for all Time periods we are getting same Customers In Top 5.
    To overcome this, we thought instead of putting condition on Bex side, we are trying to pick only first 5 rows from Bex Query and show them in Chart/Cross Tab, something like we will map only first 5 rows in Xcelcius.
    We would like to know is there any functionality in Design Studio to show only first 5 rows of data.
    Regards,
    Anil

  • Need help in SQL query to get only distinct records

    Hi all.
    I am new to oracle SQL and i want to write a query to get only distinct values from 2 tables.
    for example i hade 2 tables table1(employee_id,employee_no,grade) and another table2 with same structure.
    for example data in table1 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    1 101 D
    and data in table 2 is
    Employeeid employeeno Grade
    1 101 A
    1 101 B
    1 101 E
    i want to display only the fourth row like the data that doesnt exist in table2 i,e (1 101 D)
    I had too much records in both tables and i jst want to see the records that is in table 1 not in table 2 only.
    employeeid and employeeno are the same in both tables
    I hope u understand my query. I user left outer join and right outer join bt it displays all the results that and matching and unmatching. I want jst unmatched records.
    Any help is highly Appreciated.
    Thanx in Advance.
    I am using oracle 10G on windows

    Try MINUS:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries004.htm#i2054381
    SQL> -- generating sample data:
    SQL> with t1 as (
      2  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      3  select 1, 101, 'B' from dual union
      4  select 1, 101, 'E' from dual union
      5  select 1, 101, 'D' from dual
      6  )
      7  ,  t2 as (
      8  select 1 employeeid, 101 employeeno, 'A' grade from dual union
      9  select 1, 101, 'B' from dual union
    10  select 1, 101, 'E' from dual
    11  )
    12  --
    13  -- actual query:
    14  --
    15  select employeeid
    16  ,      employeeno
    17  ,      grade
    18  from   t1
    19  minus
    20  select employeeid
    21  ,      employeeno
    22  ,      grade
    23  from   t2;
    EMPLOYEEID EMPLOYEENO G
             1        101 D
    1 row selected.

  • Jpa native query returns only first character of a field

    Hi,
    I've a JPA native query that returns two fields from my oracle database. The first field is a CHAR(2) field with two char values in it, like 'OZ' etc.
    The problem is, as soon as the query is executed it returns only first character of field1. If the actual value of field1 is like 'OZ' then it returns only 'Z'.
    Query nativeQueryForProfileInfo = getManager().createNativeQuery(queryToRun);
    List list = nativeQueryForProfileInfo.getResultList();
    Please help,
    thanks

    There could be several explanations here and it's difficult to say without having more details, possibilities are
    There is something wrong with your display logic.
    There is something wrong with your mapping.

  • Query based report to pick up the value from differences table

    Hi,
    I am trying to pick up the value from change log differences feild but since it is system variable i am unable to pick it.which table i should pick up to get that .
    Regards-
    Monica.

    Hi Monica,
    This would be a tough job if you know the structure of the historical record tables.  You need to familiar with all those A tables first.  Any changes to one of the record would create a instance of the record before change.  AITM is for OITM, AIT1 is for ITM1 etc.  Which tables are you looking for?
    Thanks,
    Gordon

  • Pressing "shuffle" on my 7th gen Nano will only randomly pick the first song, then repeats it over and over. How do I get "shuffle to work properly?

    Pressing "shuffle" on my 7th gen Nano will only randomly pick the first song, then repeats it over and over. How do I get "shuffle to work properly?

    Is "REPEAT ONE" highlighted. If it is, touch it to de-select. Cheers!

  • Set default value for people picker only when user checks a checkbox (Sharepoint 2010)

    The javescript in below link works for me.
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/2b130f64-3db2-484a-9a53-ccbe18d2c5de/set-default-value-for-people-picker-in-list-template-current-user?forum=sharepointgenerallegacy
    However, I'd like to set default user for people picker only when user checks a checkbox. 
    I am new to  development. Could you please help me on this requirement ?
    Thank you very much. 

    Hello,
    Use this link to to validate checkbox value, if true then set the person or group value (i.e. as posted in your link).
    http://geekswithblogs.net/haniamr/archive/2011/03/10/validate-that-a-checkbox-is-checked-using-javascript.aspx
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Hello, I just purchase Adobe Premier elements 12. I installed it but the only problem is when I try to open "new project" it tells me I have to put my password in and username for the first seven days of installation, but when I do that the project never

    Hello, I just purchase Adobe Premier elements 12. I installed it but the only problem is when I try to open "new project" it tells me I have to put my password in and username for the first seven days of installation, but when I do that the project never opens, it just has the loading bar loading and then it stops, so I have no idea wat the problem is, please help

    new project help
    What computer operating system is your Premiere Elements running on?
    Have you gone through the typical drills of
    1. Latest version of QuickTime installed on your computer with Premiere Elements?
    2. Running program from User Account with Administrative Privileges as well as from Run As Administrator applied to the desktop icon
    with right click of the icon, followed by selecting Run As Administrator?
    3. Does problem exist with and without the antivirus and firewall(s) disabled?
    4. Even though the Premiere Elements 12 Editor will not open, can you open the Elements Organizer 12?
    If Yes to all of the above, please review the following for a possible solution...
    ATR Premiere Elements Troubleshooting: PE12: Premiere Elements 12 Editor Will Not Open
    Please review and consider the above and then we can decide what next which might include trying to open
    the program directly from the .exe files.  (If Windows 7, 8, or 8.1 64 bit, Local Disk C\Program Files\Adobe\
    Adobe Premiere Elements 12\ and in the Adobe Premiere Elements 12 Folder are the Adobe Premiere Elements 12.exe
    and Adobe Premiere Elements.exe files. Double click the Adobe Premiere Elements .exe file to try to open the project.)
    We will watching for your results.
    ATR

  • How to select only first few values in a Column

    Hi, in one of the column of type SDO_GEOMETRY. In that column we have many values. Example : *(-6.33787700000002, 56.547309, -6.33786800000001, 56.547279, -6.33781400000001, 56.547249, -6.33776900000001)*
    I wanted to know how can i select only first two or last two values from within the column.
    Eg: i want only -6.33787700000002, 56.547309 to be displayed
    Thanks

    Hi,
    Are the value specified here are multirow or single row data?
    if it is multi row, Karthick solution should work. Else if it is a single row then try this
    with T as
    select '-6.33787700000002, 56.547309, -6.33786800000001, 56.547279, -6.33781400000001, 56.547249, -6.33776900000001' SDO_GEOMETRY from dual
    -- end of sample data
    select substr(SDO_GEOMETRY,1,instr(SDO_GEOMETRY,',',1,&cnt)-1) Output from T
    PRAZY@11gR2> /
    Enter value for cnt: 2
    OUTPUT
    -6.33787700000002, 56.547309
    Elapsed: 00:00:00.05And remember, while posting questions it is good to specify your DB version with clear sample data and required output.
    HTH,
    Prazy

  • Defaulting value of Dropdown List to the first value of a BI Query

    Hi,
    In my VC application I have a form containing a dropdown list to be used as selection criteria for other data.  The dropdown list is dynamically populated by a BI Query.  When I run the application, the dropdown list is correctly populated with the values returned by the linked query.  However, on initial load of the iView, the default value of the dropdown list is blank.  The requirement is for the first item returned by the linked query to display as the default value.
    I would appreciate any suggestions on how to achieve this requirement.
    Thank you,
    Mustafa Bensan.

    Hi Mustafa,
    I checked your requirement but it is not possible to display first value as default value for a drop down list because the list will be generate when you click the drop down list. You can use a 'list box' instead of drop down list.
    Regards
    Basheer

Maybe you are looking for

  • How do I prevent users from returning to previous pages in a PDF with fill-in-forms?

    I am creating a presentation in Adobe Acrobat Pro and there is a test at the end. I do not want users returning to previous pages to find answers. How do I do this?

  • Need help in combining two similair SQLs into one

    DB Version:10gR2 I need to combine the following two queries into one query and return the following three columns Unprocessed Quantity1,Unprocessed Quantity2, Total Uprocessed Cost Unprocessed Quantity1 can be determined using select t.ITEM, sum(t.Q

  • Same Song On All Pages

    Hi, A client wants me to put music on his website. He wants it setup so that when people come they get music, and then when they click to another page (on the his site, not a different site), the music keeps playing, rather than starts again. What is

  • Upgrade to Photoshop Elements 7

    We are currently using Adobe Photoshop Album 2.0 (which I think is the last version) with 12,000+ images cataloged, tagged, etc.  We want to upgrade to Photoshop Elements 7.  Will we be able to do this w/o losing all the tags, etc?  If so how???

  • What's this??  (clipboard problems)

    Getting "OpenClipboard Failed" error in dreamweaver. Clipboard works in every other application. Never had a problem before. A bug?