11.2.0.3- how to sort by latest time and get mode of those values in 1 sql

Hi,
have s sql as below
select   i.ean,
  i.year_of_pubn,
  stats_mode(max(i.name) keep (dense_rank first order by i.db_timestamp desc)) name
from archive.zpx_plnt_iss_stg_bak  a,
    ARCHIVE.zpx_med_iss_stg_bak i
where a.etl_run_num_seq >= (select last_number_processed from last_processed_archive_num )
and i.etl_run_num_seq >= (select last_number_processed from last_processed_archive_num )
and a.id = i.id
group by  i.ean, i.year_of_pubnbut saying not single group by function.
Scenario is
3 records for the same grouping (ean + year) all have same timestamp, 2 of the values the same, one different wish to take the mode (i.e. one kiwth the 2 vaklues but can't seem to use stats_mode in same sql.
Any Thoughts/ideas how to do this?
Can do with with statment first but want to do in one sql if posisble without using with clause, inline views etc;.
What am i doing wrong.
Edited by: user5716448 on 24-Jul-2012 03:51

Hi,
You can do what you want to (without sub-queries) using the analytic FIRST_VALUE (or LAST_VALUE) function.
Since you didn't post any sample data, I'll use tables in the scott schema to illustrate. This shows the most common job in the highest salaray grade for each department.
SELECT DISTINCT
          e.deptno
,         FIRST_VALUE (e.job) OVER ( PARTITION BY  e.deptno
                                   ORDER BY      g.hisal     DESC
                         ,             COUNT (*)     DESC
                        )      AS top_job
FROM       scott.emp       e
JOIN       scott.salgrade  g   ON  e.sal  BETWEEN  g.losal
                                    AND       g.hisal
GROUP BY  e.deptno
,            e.job
,       g.hisal
;Output:
`DEPTNO TOP_JOB
     10 PRESIDENT
     30 MANAGER
     20 ANALYSTI suspect using a sub-query will be more efficient, as well as clearer.
Edited by: Frank Kulash on Jul 24, 2012 8:20 AM
Changed LAST to FIRST

Similar Messages

  • How to monitor OSD TS failure and get alert or report?

    How to monitor OSD TS failure and get some alert or generate an report?
    We have SCCM 2012 R2 CU1 with MDT 2013.
    I have checked the OSD reports in SCCM and everyone is emty, where do SCCM get data to the what to activate?
    (I thinking of "Task Sequence - Deployment Status" reports)
    I am not sure people read report manually or lock at the MDT monitor view. So best I think that generate an email or incident in Service Manager when an TS fails.
    We do have SCOM, SCSM, SCO.
    Is there anyone that can point what way or what option I have?
    /SaiTech

    Specifically you could use this Status Message Query syntax to monitor your Task Sequences for errors:
    select stat.*, ins.*, att1.*, att1.AttributeTime from SMS_StatusMessage as stat left join SMS_StatMsgInsStrings as ins on stat.RecordID = ins.RecordID left join SMS_StatMsgAttributes as att1 on stat.RecordID = att1.RecordID inner join SMS_StatMsgAttributes
    as att2 on stat.RecordID = att2.RecordID where att2.AttributeID = 401 and att2.AttributeValue = "DOJ200A1" and stat.SiteCode = "DOJ" and att2.AttributeTime >= ##PRM:SMS_StatMsgAttributes.AttributeTime## order by att1.AttributeTime desc
    Just replace DOJ200A1 with the Deployment ID of your Task Sequence and DOJ with your SiteCode.
    If you want to generate an alert if the TS fails then you could run a script that calls a utility (or similar) which sends a pre-configured email to a specified address (as an alternative to Torten's response). This could be placed in the built in error
    logging section of the SCCM integrated MDT Task Sequence when it fails which I assume you are using (right at the bottom, called Gather Logs and StateStore on failure).
    There are heaps of ways of generating an email from a TS and controlling error logging just do a search - as you have Service Manager you could even use your instance of Orchestrator and call a run book in your TS which does the email?
    Cheers
    Damon

  • I have the wrong apple ID on my iPhone 4 for face time and iCloud.  I have the right apple id for iTunes store.  How can I can face time and iCloud apple id?

    I have the wrong apple ID on my iPhone 4 for face time and iCloud. It has my husband's ID because he synced it to his one time.  I do my apple id for iTunes store.  How can I can face time and iCloud apple id?

    iCloud:
    Settings > iCloud > Delete Account then lock in with your Apple ID.
    FaceTime:
    Switch Settings > FaceTime > FaceTime OFF and switch back on with your Apple ID.

  • Firefox 5 has lost all my chrome tab's and capabilities which came with 4? how do I un install 5 and get back to my version 4?

    firefox 5 has lost all my chrome tab's and capabilities which came with FF4? how do I un install 5 and get back to my version 4 & retain all my bookmarks at least I's also like to retrieve my Chrome capabilities as well?

    Firefox 4 requires at least OS X 10.5 and an Intel Mac. There is a third party version of Firefox 4 that runs on OS X 10.4/10.5 and PPC Macs, for details see http://www.floodgap.com/software/tenfourfox
    If you prefer, you can get the latest version of Firefox 3.6 from http://www.mozilla.com/en-US/firefox/all-older.html
    Mozilla are working to prevent Mac users with non-compatible systems from getting the notification about Firefox 4, and also not displaying the "Download Firefox 4" button on http://www.mozilla.com

  • How to track the login time and logout times of clients

    hai
    please give me the solution
    suppose there are 5 systems connected in LAN.
    how to track the login time and logout times of clients
    for a given time(may be one day or 1 hour) using any programming language.
    please give me the solution

    When the client logs in you write the client's ID and the current time to a database. Likewise when the client logs out. Assuming of course that you have a program that knows when those events occur.

  • What is the best way to enlarge a part of a photo in lightroom?  How much cn you enlarge it and get

    what is the best way to enlarge a part of a photo in lightroom?  How much cn you enlarge it and get an acceptable result?

    The way I would do it would be to crop the image so that it only displays what you want, then export that image and specify the dimensions. You will have to experiment with different export sizes to determine what would be acceptable for your situation. You might be more forgiving or more demanding than anyone who would venture to answer that question. That's the nice part about digital photography; you can experiment to your heart's content until you get the result you are looking for.

  • How do I insert new record and get results on a landing page

    how do I insert new record and get results on a landing page

    It's not clear from your post what you are asking. In a SQL database, you use the INSERT statement to insert a row into a table. You use the SELECT statement to retrieve rows. Here's some basic info on how to do that within PHP
    PHP MySQL Insert Into
    PHP MySQL Select

  • When I'm bouncing a project, it freezes or doesnt stop bouncing and keeps going past its cut off. how do i make it stop and get back to normal?

    When I'm bouncing a project, it freezes or doesnt stop bouncing and keeps going past its cut off. how do i make it stop and get back to normal?

    Hi
    chorleyman wrote:
    you do have to actually define the area to be bounced in the dialogue window that comes up - there are some discrepencies in the way that the program behaves like that,
    Apart from the "Include Audio Tail" function, which can leave Logic bouncing for a very, very long time, there are generally, no discrepancies regarding the Bounce Locators:
    If Cycle is enabled, the bounce locators will be set to the cycle locators.
    If Cycle is off, and regions are selected, the bounce locators will be set to the selection.
    If cycle is off, and no regions are selected, the bounce locators will be set from the Project Start to the project end.
    It is smart to actually check that the bounce locators are set where you would like them to be.
    wildfire31 wrote:
    When I'm bouncing a project, it freezes or doesnt stop bouncing and keeps going past its cut off. how do i make it stop
    If you get caught with a bounce that does not stop, Command . (period) should do the trick.
    CCT

  • HT201210 I was updating my itunes on my ipad from my pc and my ipad has now shut down and shows a lock with arrow leading to itunes on screen. How do i unlock my ipad and get it working again?

    I was updating itunes on to my ipad from my pc and now my ipad has shut down and shows a lock with an arrow pointing to itunes. How do I unlock my ipad and get it back to working again?

    Make sure you have the Current Version of iTunes Installed on your computer
    iTunes free download from www.itunes.com/download
    Then... see Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...  Be sure to Follow ALL the Steps...
    Take your time... Pay particular attention to Steps 3 and 4.
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766
    Note.  Once the Device is asking to be Restored with iTunes... it is too late to save anything... and you must continue with the Recovery...

  • I was not aware of the automatic renewal of subscriptions and was chareged on 4/27 for another year of The Daily. How do I cancel the suscription and get reinbursed?  I have recently found how to manage and shut off future renewals. Can i get a refund?

    I was not aware of the automatic renewal of subscriptions and was charged on 4/27 for another year of The Daily. How do I cancel the suscription and get reinbursed? I have now shut off automtatic renewals. It would have been nice to know it was there to begin with!

    Edge has very clear restrictions, one being that you must have 6 months of clean payment history which you don't. Either wait until April 14, or good luck at Sprint.
    I am unsure how it can be determined the payment mix up was the fault of CS, but regardless, the mix up was done. There can be any number of reasons why a payment could be missed without any fault on your part, however you are still the responsible party for the account and must live with the repercussions.

  • Time machine: I get the following message: The backup disk image "/Volumes/Data-1/Clemens's iMac.sparsebundle" is already in use - what to do? Where and how do I find that file and get rid of it?

    time machine: I get the following message: The backup disk image “/Volumes/Data-1/Clemens’s iMac.sparsebundle” is already in use - what to do? Where and how do I find that file and get rid of it?

    I'm on Mountain Lion and have version 6.1 of AirPort utility so there is no button to "Disconnect All Users"and the only other option of "removing and re-selecting the drive via Time Machine Prefs" doesn't work either. So this will work.
    Launch Airport Utility and select the TC "Edit" button, then select the Disks tab. Deselect "Enable File Sharing" and click "Update". The TC will reboot then follow the same procedure and reselect "Enable File Sharing" and click "Update". After TC reboots again you'll be up and running. Not the neatest way to do it but saves having to unplug the TC which risks disk damage and the whole procedure takes less than a minute.The "Enable File Sharing" button seems to have replaced the "Disconnect All Users" button but with the slight disadvantage that it reboots the TC which takes up additional time.

  • How to measure query run time and mnitor performance

    Hai All,
                   A simple question. How to measure query run time and mnitor performance? I want to see the parameters like how long it took to execute, how much space it took etc.
    Thank you.

    hi,
    some ways
    1. use transaction st03, expert mode.
    2. tables rsddstat*
    3. install bw statistics (technical content)
    there are docs on this, also bi knowledge performance center.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3f66ba90-0201-0010-ac8d-b61d8fd9abe9
    BW Performance Tuning Knowledge Center - SAP Developer Network (SDN)
    Business Intelligence Performance Tuning [original link is broken]
    also take a look
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ce7fb368-0601-0010-64ba-fadc985a1f94
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c8c4d794-0501-0010-a693-918a17e663cc
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/31b6b490-0201-0010-e4b6-a1523327025e
    Prakash's weblog on this topic..
    /people/prakash.darji/blog/2006/01/27/query-creation-checklist
    /people/prakash.darji/blog/2006/01/26/query-optimization
    oss note
    557870 'FAQ BW Query Performance'
    and 567746 'Composite note BW 3.x performance Query and Web'.

  • I have received an email receipt charging me $109.99 for an app I've never heard of and definitely never downloaded. How do I report the problem and get a refund?

    I have received an email receipt charging me $109.99 for an app I've never heard of and definitely never downloaded. How do I report the problem and get a refund?

    Log into your iTunes account, then click on previous purchases then select the purchased app and then click report a problem.  Then write and explain your problem and I am sure it will be considered. 
    Also change your iTunes password as soon as possible.

  • I "sent as gift" two songs to a friend. She can't find them. Are they sent to her in an email? Will they download during a sync? How can we recover the songs and get them to her iPhone?

    I "sent as gift" two songs to a friend. She can't find them. Are they sent to her in an email? Will they download during a sync? How can we recover the songs and get them to her iPhone?

    Try going to iTunes Store from the left column, then Account, then Purchase History, then Manage Gifts.

  • TS3276 How do I send an email and get a receipt that they opened it? I have seen this before, but don't know what setting to go to.

    How do I send an email and get a recipt that they opened it?

    Additionally, even if Mail supported it, the recipient would have to allow/consent to sending you the receipt - if I were the recipient, I would certainly not allow it. If you are sending legal or other very important files, use the "return receipt required" feature of US Mail - you will get a receipt that it was accepted with a signature.

Maybe you are looking for