Query For Retrieving Data With Date and grouping

Hi Guys
I am having a hard time to figure out the sql query.
I have a table with data. Below is the illustration.
date location  item description
1 jan 14 A  apple desc1
2 jan 14 A  apple desc2
3 jan 14 B  apple desc1
4 jan 14 B  apple desc2
1 jan 14 A  orange desc1
2 jan 14 A  orange desc2
3 jan 14 B  orange desc1
4 jan 14 B  orange desc2
My question it how to get the latest date on each location and item along with the description field
This is the result I want
date location  item description
2 jan 14 A  apple desc2
4 jan 14 B  apple desc2
2 jan 14 A  orange desc2
4 jan 14 B  orange desc2
Thanks.

provided it a datetime/date field you've for date you can do this
SELECT [date],location,itemdescription
FROM
SELECT [date],location,itemdescription,
ROW_NUMBER() OVER (PARTITION BY location ORDER BY [date] DESC) AS Rn
FROM table
)t
WHERE Rn = 1
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Cannot get wanted data with MAX and GROUP BY function

    Hi
    All
    I have a table like below:
    COLUMN     TYPE
    USER_ID     VARCHAR2 (10 Byte)
    PROCESS_ID     VARCHAR2 (30 Byte)
    END_TIME     DATE(STAMP)
    TO_LOC     VARCHAR2 (12 Byte)
    TO_LOC_TYPE     VARCHAR2 (15 Byte)
    FROM_LOC      VARCHAR2 (12 Byte)
    ITEM_ID     VARCHAR2 (25 Byte)
    CASES     NUMBER (12,4)
    LMS_UDA1      VARCHAR2 (250 Byte)
    ZONE     VARCHAR2 (2 Byte)
    I only want get one record with all columns, only have one clause MAX(END_TIME)
    But the other column have difference value.
    when i use MAX(END_TIME) and GROUP BY USER_ID,PROCESS_ID,CASES,....
    the sql didnot give one record,
    It give many records
    Please help me on this
    Regards
    Saven

    Hi, Saven,
    Sorry, it's unclear what you want.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show your proiblem using commonly available tables, like those in the scott or hr schamas, then you don't have to post any sample data: just the results and the explanation.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    Are you trying to see all data related to the highest (that is, latest) end_time?
    I think you want something like this, that finds all the ionformation about the employee with the latest hiredate:
    WITH     got_r_num     AS
         SELECT     emp.*
         ,     ROW_NUMBER () OVER (ORDER BY  hiredate  DESC  NULLS LAST)
                   AS r_num
         FROM     scott.emp
    SELECT     *     -- Or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;What do you want in case of a tie, that is, if 2 or more rows have the same latest end_time? You may need to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMEBR

  • SAP query for asset report with retirement and depreciation retirement

    Hi Expert,
    Can anyone tell me in table ADA which filed is holding the figure of retirement and retirement depreciation?
    Thank oyu

    Hi,
    Max.
    For your question you can check the tables ANEP for asset transactions line items and for asset value fields you can check out ANLC.
    I hope this may help you.
    If you have any doubts feel free to ask.
    Regards,
    Pankaj A Bhalerao.

  • What Are The Minimum Permissions In Order An User To Be Able To Access User Profile Data With JavaScript And REST API

    The question says it all:
    What Are The Minimum Permissions In Order An User To Be Able To Access User Profile Data With JavaScript And REST API.?
    In the User Profile -> Permissions there is only the option for "Full Control".

    Hi Nikolay,
    Thanks for posting your issue, you need to set permissions on User Profiles = Read. Kindly find the below mentioned URLs to get the code and more details on this.
    http://www.vrdmn.com/2013/02/sharepoint-2013-working-with-user.html
    http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html
    http://sharepoint.stackexchange.com/questions/61714/sharepoint-2013-call-the-rest-api-from-sharepoint-hosted-app
    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/04/09/how-to-query-sharepoint-2013-using-rest-and-javascript.aspx
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • Hard currency is not valuated in FAGL_FC_VAL along with local and group currency

    Hi All,
    I have the below system settings for FOREX revaluation. The revaluation is not happening for Hard currency along with local and group currency. The test data and other settings seams to be fine as the below mentioned workaround works perfectly for hard currency revaluation.
    I would like to take your expert feedback on this issue to confirm whether this is how SAP works or its an issue with FAGL_FC_VAL program.
    System Settings:
    Currencies in company code
    local currency      group currency      hard currency
    10                             30                         40
    USD                          USD                    UYU
    FOREX settings:
    Work around found:
    Define two Valuation area, say
    1. Valuation Area: A1 which will have currency type 10 and 30.
    2. Valuation Area: A2 which will have only the currency type 40.
    3. Run FAGL_FC_VAL twice for these area.
    Issue with this work around:
    1. The valuation area is assigned to one accounting principle (which is in turn assigned to a specific ledger).
    2. Thus, if I have different accounting FOREX process to be followed in different ledgers (say IFRS ledger, Local Ledger, Tax ledger) then I need to create 2 valuation area (as per above workaround) for each ledgers and run FAGL_FC_VAL for each of these valuation areas.
    Thanks & Regards
    Nikhil Kothari

    Hi Experts,
    Any views on the above issue?
    Thanks & Regards
    Nikhil Kothari

  • How i map the caf data with data of UWL in web dynpro

    Hi Experts,
    i created a bpm project with nwce 7.1.1 and it have a independent caf to keep it's data and status.
    now i have to create a view(use web dynpro) such like UWL,
    my question is
    how i map the caf data with UWL, and let the view can open the task(popup a window, just like UWL do) for user to finish their job?
    thanks.

    Hi Vic
    Your requirement is exect functionality of UWL based on WEBDYNPRO, CAF and BPM for automation? ,and question is How to use CAF with WD or CAF with UWL API's ?. please clarify it.
    Please fo through from given doc misght give u some idea
    1. [How to develop Web Dynpro UI for your CAF project |http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417300)ID0722080650DB02400261803144436507End?blog=/pub/wlg/5414]
    Best Regards
    Satish Kumar

  • Integration documentation for sap sd with fico and mm

    hi Sappers,
    I need Documentation for SAP SD with FICO and MM Module
    its very urgent.
    mail id : [email protected]

    <b>Some basic information :</b>
    FI-MM: The integration between FI-MM happens in T-code: <b>OBYC</b>
      1. When PO is created :
    No Entry -
      2. When GR is posted 
          Inventory Account dr (Transaction Key BSX in OBYC)
                To GRIR account (T.Key WRX in T-code OBYC)
      3. When Invoice is posted
          GRIR account Dr.
          Vendor account  Cr.
      4. Payment made to Vendor
          Vendor A/c Dr
                To Bank Clearing A/c Cr.
    Points to know : Movement Types, Assignment of Movement types to T-keys (T-code OMJJ), Value string (I also need some information on this) , OMWN and OMWB transactions. 
    There is a close integration b/w FI & MM, actually document flows from MM to FI in the following areas such as,
    <u> 1. Movement Types:</u>
    Used to enable the system to find the predefined posting rules determining how the accounts of financial accounting system are to be posted & to update the stock fields in the matrl master data.(Goods Receipt, Goods Issue, etc)
    <u> 2. Valuation Class:</u>
    Assignment of material to grp of gl account, used to determine the gl accounts that are updated as a result of goods movement.
    <u>3. Transaction/Event key:</u>
    Used to control the storage or filing of documents & assignment of documents.Used to differeniate b/w various transactions such as goods movement tht occur in inventory.
    <u> 4. Material Type:</u>
    Each material should assign mtrl type in mtrl master record used to update whether changes made in qty are updated in material master record & change in value also updated in stock account.
    <u><b> FI-SD Integration:</b></u>
    The integration is done in T-code VKOA
    <u>  1. Sales Order Created</u> 
            -No Entry-
      <u>2. PGI done (Goods issue)</u>
          Cost of Goods Sold     Dr (Configured in OBYC GBB T-Key)
               To Inventory Account
    <u>  3. Billing document released to Accounting</u>
            Customer Account Dr.
                  To Sales Revenue Account (ERL T-key in Pricing procedure)
      Note : The GL account is assigned to this ERL in VKOA
    <u> 4. Payment Received</u>
            Bank Clearing A/c Dr
                           Customer A/c Cr. 
    Points to Know : Good to understand the pricing procedure and how the different transaction keys are used like ERL, ERS etc

  • Performance question when compare date with date or char with char

    Hello from Germany (Frankfurt) !
    I am working on Oracle 9.2.0.8.0
    and have to solve following problem:
    Comparison of a date and char fields.
    Now two ways to do it.
    Either I compare char with char and convert date to char,
    or I compare date with date and convert char to date.
    Now the performace question. Which operation takes more effort for the database?
    So why not to try and to see the results?
    First create table:
    CREATE TABLE TEST (
    char_date VARCHAR2(8),
    real_date DATE
    NOLOGGING;
    Then insert 1.000.000 rows
    BEGIN
    for x in 1..1000000
    loop
    insert into test (char_date, real_date) VALUES('19990101', TO_DATE('2006.01.01', 'YYYY.MM.DD'));
    end loop;
    COMMIT;
    END;
    Collect statistics
    EXEC dbms_stats.gather_table_stats('TESTER', 'TEST');
    Now run some selects for date to char conversion:
    Elapsed: 00:00:00.00
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    Elapsed: 00:00:03.02
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    And some selects for char to date conversion:
    Elapsed: 00:00:03.02
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL>
    As you see when I compare char with char and convert date to char it seems to be faster (almost 1 second)
    Is the test correct?
    I still not sure, what gets better performance...
    Any idea?
    Thanks!

    Depends on whether you want the right results or not.
    Why don't you run the following two queries and see if the difference in results tells you anything?:
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  date_col < to_date('04/03/2006', 'dd/mm/yyyy');
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  to_char(date_col) < '04/03/2006';

  • Logs are generating with owner and group as 'root'

    Hi,
    In our newly installed and configured Oracle application server(10.1.3.5), the logs are generating with owner and group as 'root'.
    Location: $ORACLE_HOME/Apache/Apache/logs
    -rw-r----- 1 root root 6700 Apr 3 02:03 access_log.1364947200
    -rw-r----- 1 root root 430 Apr 3 02:04 error_log.1364947200
    We have configured it on port 80. For this the '.apachectl' ownership and permissions are changed as below:
    -rwsr-s--- 1 root dba 1703780 Jul 21 2009 .apachectl
    Kindly let me know what are the changes to be made, for the logs to be generated with the group as 'dba' instead of 'root'.
    Thanks.
    Edited by: 985284 on Apr 3, 2013 3:14 AM
    Edited by: 985284 on Apr 3, 2013 4:22 AM

    Ok - that is quit weird then. If you want to run the HTTP Server on a privileged port, you basically change the ownership of the .apachectl executable :
    cd ORACLE_HOME/Apache/Apache/bin
    chown root .apachectl
    chmod 6750 .apachectlas per [url http://docs.oracle.com/cd/B25221_05/core.1013/b25209/ports.htm#CIHJEEJH]documentation.
    Your user and group directive should be set to :
    User oracle
    Group dbaUpon starting, the http server would start as root and then switch the effective userid of the process from root to oracle. In the process list (ps -ef | grep httpd), you should see oracle.
    Do you have the same configuration and what do you see in the process list?

  • How to create sql query for item master with operator LIKE with variables?

    hi all,
    How to create sql query for item master with
    operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
    Jeyakanthan

    Hi Jeyakanthan,
    here is an example (put the like statement into the where field)
    SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
    The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
    Regards Steffen

  • Hello. It can be a iPhone4 accessories for the one with pictures and other things are transferred wirelessly to a TV? Thank you

    Hello. It can be a iPhone4 accessories for the one with pictures and other things are transferred wirelessly to a TV? Thank you 

    You need an Apple TV to be able to wirelessly send pictures etc. from iPhone.
    However you can buy an adapter if you want to connect to a TV
    http://store.apple.com/us/product/MC953

  • Laptop monitor choice for photo editing with lightroom and photoshop

    Hi,
    i'm going to buy a laptop, mostly for photo editing with lightroom and photoshop use.
    I'm in trouble with the display choice.
    One laptop has LG LP156WF4 or AUO B156HAN01 display, that should be very similar matte ips display with 55%-60% coverage of AdobeRGB. You can find a review in the "Display" section of these link : http://www.notebookcheck.net/Review-Clevo-W650SJ-Schenker-M504-Barebones-Notebook.114329.0 .html
    The other laptop hasAU Optronics B156HW01 V.4 Matte 95%, that is a TN matte display with  95% coverage of AdobeRGB. You can find a review in these link (the display should be the green bar): http://www.anandtech.com/show/4649/mythlogic-pollux-1400-clevos-w150hr-tested/6
    My question is: which one is better for photo editing with photoshop and lightroom?
    Someone says that ips is better because of the fidelity of color reproduction, view angles and contrast.
    Someone, on the other side, says that the TN 95% is better because of the gamut%.
    Can you help me?
    Thanks,
    Marco Grechi

    Macbook pro is out of budget
    Hp assistance said that in italy they don't sell laptop with dreamcolor (i'll call again tomorrow to be sure ) but i think that it would be out of budget (max 2000 euro).
    They said that the best solution for me is the zbook 15 g2 (2300 euro), but they DON'T know brand and model of the display and if i can have SSD + HD inside the zbook 15 g2.
    The laptop with the lg panel costs 1500 euro. the question is; "i know that the lg display is not the best, but is it almost sufficient for my use?". In this way i may save 500/800 to buy a separated display later.
    I have read that dell xps 15 and dell precision m3800 have great display, but they are glossy and very reflective. Is it a big handicap?
    Do you know the 3k 15,6" display Panasonic VVX16T020G00 ? It should be a 8-bit display with 72%NTSC gamut ( http://www.panelook.com/VVX16T020G00_Panasonic_15.5_LCM_parameter_22014.html )
    Do you sugget me a 3k display for photo editing?
    Thanks

  • Query For Retrieving Data With Date

    Hi Guys
    I am having a hard time to figure out the sql query.
    I have a table with data. Below is the illustration.
    date location
    item
    1 jan 14 A
    apple
    2 jan 14 A
    apple
    3 jan 14 B
    apple
    4 jan 14 B
    apple
    1 jan 14 A
    orange
    2 jan 14 A
    orange
    3 jan 14 B
    orange
    4 jan 14 B
    orange
    My question it how to get the latest date on each location and item
    This is the result I want
    date location
    item
    2 jan 14 A
    apple
    4 jan 14 B
    apple
    2 jan 14 A
    orange
    4 jan 14 B
    orange
    Thanks.

    Try the below:
    create table #temp (sdate datetime,location char(1),Item varchar(20))
    insert into #temp values('1 jan 14','A','Apple')
    insert into #temp values('2 jan 14','A','Apple')
    insert into #temp values('3 jan 14','B','Apple')
    insert into #temp values('4 jan 14','B','Apple')
    insert into #temp values('1 jan 14','A','Orange')
    insert into #temp values('2 jan 14','A','Orange')
    insert into #temp values('3 jan 14','B','Orange')
    insert into #temp values('4 jan 14','B','Orange')
    ;With cte as
    Select * , Row_Number()Over(partition by location, item order by sdate desc) Rn
    From #Temp
    Select * From cte Where rn=1 Order by Item asc,location asc
    drop table #temp

  • Estimated delivery dates for iPad 4 with wifi and cellular UK

    I have ordered the new iPad 32gb With wifi and cellular data and on my account it just says late November. Is there any way to find out a more specific date as I am going away and want to take it with me?? Would I have to ring Apple and ask?

    No one here will know
    I doubt ringing will change anything as Apple
    will update orders as soon as they can see supply to apply to the orders
    You will find the number for UK on the  order document

  • Query regarding Min function with Date

    Dear All,
    I have written query as follows but it is giving me error message.
    Selection CityCode, CityName, Min(Date)
    from Entry
    I want to write a query which should generate minimum date of transactions of city. There are about 50 cities in the Entry table and against each city there are thousands of records, I want to display only the oldest date against each city with its code. In the out put there should 50 rows as there are 50 cities and oldest (min) date. Can any one please help on this SQL.
    Thanks

    Do you want just min date in the table or need grouping by citycode and city name also?
    If just min date of the table is needed, use row_number analytic function to get the min date in the table.

Maybe you are looking for

  • How can you SELECT via Database Link CLOB data using Application Express?

    Customer Issue: Developer using Oracle's Application Express 3.1. The Developer is trying to SELECT a CLOB datatype column from a remote (10.2.0.3) database, via a database link on her 10.2.0.4 based client Application. The Developer wants to be able

  • The Sun Java Application Server 8.1 could not start anymore

    Very incredible I was working fine from may days with Stydio Creator 2 but yesterday I run the project and it does not work anymore, please can you suggest something: The Sun Java Application Server 8.1 could not start. from the Output console: C:\Su

  • Have sound but no picture....until I unplug it

    Since having the TV service hooked up about 3 weeks ago, I have had to reset my stb by unplugging it because at least a dozen times I have turned the TV on to find that I have sound but no video.  I have my TV up via HDMI for the video and my sound i

  • Why Doesnt the Time Capsule show up my New Raid Setup External HD?

    I purchased a new enclosure for a RAID 1 setup (2, 1TB hard drives) and plugged it into my MacBook PRO to use disk utility to set up. The setup was fine. I then plugged this unit into the Time Capsule UBS port and it shows up on the airport applicati

  • Read out loud feature

    I recently purchase a Satellite P755-S5263. I am not sure if the issue is with Adobe Reader X or my new Satellite laptop. I can not play a pdf CD. I know the speakers and sounds work as music CDs work, but not when I try to play my book on a pdf file