How to Get the min,max and original values in a single query

Hi,
I have a task where in i have to the min , max and the original values of  a data set .
I have the data like below and i want the target as well as mentioned below
SOURCE
DATASOURCE
INTEGRATIONID
SLOT_DATE
SLOT1
SLOT2
SLOT3
SLOT4
SLOT5
SLOT6
SLOT7
SLOT8
SLOT9
SLOT10
1
101
201111
100
100
200
100
100
100
300
300
300
300
1
101
2011112
200
200
200
200
100
100
100
100
200
300
TARGET
DATASOURCE
INTEGRATIONID
SLOT_DATE
SLOT_VALUE
SLOT MIN
SLOT_MAX
SLOT NUMBER
1
101
201111
100
1
2
SLOT1
1
101
201111
100
1
2
SLOT2
1
101
201111
200
3
3
SLOT3
1
101
201111
100
4
6
SLOT4
1
101
201111
100
4
6
SLOT5
1
101
201111
100
4
6
SLOT6
1
101
201111
300
7
10
SLOT7
1
101
201111
300
7
10
SLOT8
1
101
201111
300
7
10
SLOT9
1
101
201111
300
7
10
SLOT10
1
101
2011112
200
1
4
SLOT1
1
101
2011112
200
1
4
SLOT2
1
101
2011112
200
1
4
SLOT3
1
101
2011112
200
1
4
SLOT4
1
101
2011112
100
5
8
SLOT5
1
101
2011112
100
5
8
SLOT6
1
101
2011112
100
5
8
SLOT7
1
101
2011112
100
5
8
SLOT8
1
101
2011112
200
9
9
SLOT9
1
101
2011112
300
10
10
SLOT10
e
so basically i would first denormalize the data using the pivot column and then use min and max to get the slot_start and slot_end.
But then i
can get the min and max ... but not the orignal values as well.
Any thoughts would be appreciated.
Thanks

If you want to end up with one row per slot per datasource etc, and you want the min and max slots that have the same value as the current slot, then you probably need to be using analytic functions, like:
with t as
(SELECT 1 datasource,101    INTEGRATIONID, 201111     slotdate, 100    SLOT1, 100        SLOT2,    200    slot3, 100    slot4, 100    slot5, 100    slot6, 300    slot7, 300    slot8, 300    slot9, 300 slot10 FROM DUAL  union all
SELECT 1,    101,    2011112,    200,    200,    200,    200,    100,    100,    100,    100,    200,    300 FROM DUAL),
UNPIVOTED AS
(SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,1 SLOT,SLOT1 SLOT_VALUE
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,2 SLOT,SLOT2
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,3 SLOT,SLOT3
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,4 SLOT,SLOT4
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,5 SLOT,SLOT5
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,6 SLOT,SLOT6
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,7 SLOT,SLOT7
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,8 SLOT,SLOT8
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,9 SLOT,SLOT9
FROM T
UNION ALL
SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,10 SLOT,SLOT10
FROM T)
select DATASOURCE,INTEGRATIONID,SLOTDATE,slot,slot_value,min(slot) OVER (partition by datasource,integrationid,slotdate,rn) minslot,
    max(slot) OVER (partition by datasource,integrationid,slotdate,rn) maxslot
FROM   
  select DATASOURCE,INTEGRATIONID,SLOTDATE,max(rn) over (partition by datasource,integrationid,slotdate order by slot) rn,slot,slot_value
  FROM
    (SELECT DATASOURCE,INTEGRATIONID,SLOTDATE,slot,slot_value,
          case when row_number() over (partition by datasource,integrationid,slotdate order by slot) = 1 or
          lag(slot_value) over (partition by datasource,integrationid,slotdate order by slot) <> slot_value
              then row_number() over (partition by datasource,integrationid,slotdate order by slot)
              ELSE null
              END rn
    from unpivoted
order by DATASOURCE,INTEGRATIONID,SLOTDATE,slot 

Similar Messages

  • Does anyone know how to get the vendor ID and product ID for NI-Visa? TIA

    Does anyone know how to get the vendor ID and product ID for NI-Visa? TIA

    This question has already been addressed in this thread:
    Does anyone know how to get the vendor ID and product ID for a USB device in NI-Visa?
    John M
    National Instruments

  • Does anyone know how to get the vendor ID and product ID for a USB device in NI-Visa? TIA

    Does anyone know how to get the vendor ID and product ID for a USB device in NI-Visa? TIA

    Hello,
    Exactly which USB device are you referring to? Is the device a NI product?
    The Product ID for National Instruments DAQPad-6020E is 0x12C0. The USB vendor ID is 0x3923. This is a 16-bit hexadecimal number(1093) (that is decimal 4243).
    Also, here's a document on our website that will help you in configuring NI-VISA to control your USB device:
    http://zone.ni.com/devzone/conceptd.nsf/webmain/6792BAB18242082786256DD7006B6416?opendocument
    Swapnil P.
    National Instruments Engineer

  • I have been charged 274.55 from 8-23-2013 - 8-26-2013. These are not my charges. I need to know how to get the charges reversed and put back on my account ASAP. Please confirm!

    I have been charged 274.55 from 8-23-2013 - 8-26-2013. These are not my charges. I need to know how to get the charges reversed and put back on my account ASAP. Please confirm!

    You can contact iTunes Support via this page (we are fellow users here on these forums) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • When I went and connected  phone to my laptop and hit restore and it got rid of everything my photos my contacts everything and I don't know how to get the stuff back and if you need to know I have an IPhone4S

    When I went and connected my phone to my laptop and hit restore and it got rid of everything my photos my contacts everything and I don't know how to get the stuff back and if you need to know I have an IPhone4S

    I take it you were replacing an older iPhone and this was the first time you plugged it in? If so, that's what happens. It restored the backup of your old phone. A backup of the current phone is not made in those circumstances.
    If that's not what happened, you need to clarify.

  • How to get the Equipements number and desciption for the contract item ?

    Hi Gurus,
            How to get the Equipements number and desciption for the contract item items? It would gr8 helpful to me...
    VBAP,,EQUI,,,,,,?
    Thanks
    Krisna

    Check with below tables :
    EQUI    Equipment master data
    EQKT   Equipment short text
    EQUZ   Equipment time segment
    Thanks
    Seshu

  • How to calculate the individual sums of multiple columns in a single query

    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    Thanks

    user13667036 wrote:
    Hello,
    Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: http://stackoverflow.com/questions/16529721/how-to-calculate-the-individual-sums-of-multiple-columns-in-a-single-query-ora
    Will appreciate any help or suggestion.
    ThanksLooks like you want a simple group by.
    select
              yr
         ,      mnth
         ,      region
         ,     sum(handled_package)
         ,     sum(expected_missing_package)
         ,     sum(actual_missing_package)
    from test
    group by
         yr, mnth, region
    order by      
         yr, mnth, region;I wouldn't recommend storing your data for year / month in 2 columns like that unless you have a really good reason. I would store it as a date column and add a check constraint to ensure that the date is always the first of the month, then format it out as you wish to the client.
    CREATE TABLE test
         year_month                              date,
        Region                     VARCHAR2(50),
        CITY                       VARCHAR2(50),             
        Handled_Package            NUMBER,       
        Expected_Missing_Package   NUMBER,   
        Actual_Missing_Package     NUMBER
    alter table test add constraint firs_of_month check (year_month = trunc(year_month, 'mm'));
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-12', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
    ERROR at line 1:
    ORA-02290: check constraint (TUBBY.FIRS_OF_MONTH) violated
    Elapsed: 00:00:00.03
    ME_XE?Insert into TEST (year_month, REGION, CITY, HANDLED_PACKAGE, EXPECTED_MISSING_PACKAGE, ACTUAL_MISSING_PACKAGE)
      2  Values (to_date('2012-nov-01', 'yyyy-mon-dd'), 'Western', 'San Fransisco', 200, 10, 5);
    1 row created.
    Elapsed: 00:00:00.01
    ME_XE?select
      2        to_char(year_month, 'fmYYYY')    as year
      3     ,  to_char(year_month, 'fmMonth')   as month
      4     ,  Region
      5     ,  CITY
      6     ,  Handled_Package
      7     ,  Expected_Missing_Package
      8     ,  Actual_Missing_Package
      9  from test;
    YEAR         MONTH                REGION                         CITY                    HANDLED_PACKAGE EXPECTED_MISSING_PACKAGE ACTUAL_MISSING_PACKAGE
    2012         November             Western                        San Fransisco                       200                       10                      5
    1 row selected.
    Elapsed: 00:00:00.01
    ME_XE?Then you have nice a nice and easy validation that ensures you data integrity.
    Cheers,

  • How to get the x1,y1 and z1 coordinates out of an sdo_geometry object?

    Hello,
    i have stored several boxes into an sdo_geometry object like the following:
    mdsys.sdo_geometry(3003,null,null,
    mdsys.sdo_elem_info_array(1,1003,3),
    mdsys.sdo_ordinate_array(x1,y1,z1,x2,y2,z2)
    now i would like to get the x1,y1,z1 coordinates from the boxes. how can i get them with a simple sql-statement?
    When i do "SELECT v.shape.sdo_ordinates ..." then i get a sdo_ordinate_array. But how can i get only the first coorinates?
    I know how it works to get x1,y1 and z1 over a java-prog. But i want to get them with a sql-statement as i also want to get the min and max x1,y1,z1.
    Hope there is anybody that can help me. Thanks in advance.
    Markus Veith

    You can get coordinates from an SDO_POINT_TYPE as follows:
    SELECT      t.GEOMETRY.SDO_POINT.x,t.GEOMETRY.SDO_POINT.y
    FROM      TABLE T
    (where geometry is the geometry column and table is the geometry table, note
    that a table alias must be used.)
    Getting the coordinates from the SDO_ORDINATES is a little trickier.
    You'll need to use a loop in PL/SQL, eg:
    SET SERVEROUT ON
    DECLARE
    i number;
    j NUMBER;
    BEGIN
    FOR sel IN (SELECT <geom_column> FROM <geom_table> WHERE ROWNUM < 10) LOOP
    i := 1;
    while i < sel.<geom_column>.sdo_ordinates.count LOOP
    j:= sel.GEOMETRY.sdo_ordinates(i);
    dbms_output.put_line(j);
    i := i + 1;
    j:= sel.GEOMETRY.sdo_ordinates(i);
    end loop;
    dbms_output.put_line(j);
    END LOOP;
    END;
    This will print the SDO_ORDINATES to the SQLPLUS screen, put a WHERE clause to reduce output.
    To use these values in a query, put them in a cursor.

  • How to Get the Login Window and/or Bypass Login Items?

    Greetings, folks!
    This is a silly question, but the old standby of “hold down the shift key” doesn’t work in 10.6.1:
    What key(s) need to be pressed to get the LogIn window and then after LogIn, to bypass LogIn Items?
    Thanks!!
    Richard Fairbanks

    Not here, on a fresh (erased) install.
    Pressed either before or after the initial gray Mac appears, the shift key does not access the LogIn screen. It is possible to bypass the account’s LogIn items by holding down the shift key after the LogIn screen has been called and successfully commenced, but how does one call the Login screen when the Mac is normally set up for automatic login?
    It used to be the shift key . . . 
    Thanks!

  • How to get the client date and time ?

    Dear Sirs...
    Using jdeveloper 10.1.2.0
    How can i get the client date and time using the HttpServletRequest ?
    thanks for any help in advance
    best regards

    If your code is running on the client pc you can just create a new instance of the java.util.Date class. That class automatically defaults to the current time of the client machine. Otherwise if you're running the code on the server, you could insert/post the client date/time by adding its string representation as a parameter to the HTTP request object.
    Ronald

  • How to get the class name and field name dynamically

    Hi
    I have a class (ex: Contract) the fields (ex : a,b,c) .i need to get the class name and field name dynamically
    ex
    if( validation file for the field Contract.a){
    return contract.a;
    }else if(validation file for the field Contract.b){
    return contract.b;
    how to pass the field name and object dynamically
    Please help me .............
    Thanks in Advance..
    Edited by: 849614 on Aug 11, 2011 6:49 AM

    YoungWinston wrote:
    maheshguruswamy wrote:
    Agreed, but IMO, i still feel its best if there is no tie in between consumer class level details and the database it talks to. A service layer is needed in between them.Sounds like you've done a bit of this before. Me, I've either been a modeller/DBA, doling out data, or a nuts and bolts programmer (and actually more toolmaker than apps, but did a bit of that too).
    Do you know of a good book about the "middle ground" (ie, these service layers)? I understand it empirically, but haven't had a lot of exposure to it.
    Winston
    Edited by: YoungWinston on Aug 11, 2011 10:34 PM
    PS: Apologies. Edited my previous post, presumably while you were composing your reply, when I finally realized what '.filed' meant.Most of my work is in web development, never been a DBA :) . The biggest 'concern' in my shop is 'separation of concerns'. The UI group reports up to a different IT head, the DB group reports up to a different IT head and so on. The looser the coupling between these systems, the lesser the project costs (Integration, QA etc) are. Martin Fowler's books contain good information about separation of concerns in an enterprise environment. The two books which i recommend are
    [url http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420]Enterprise Application Architecture and
    [url http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683/ref=pd_sim_b_1]Enterprise Integration Patterns

  • OIM: How to get the last operation and data from a child form action

    Dear OIM guru,
    I have a regular Process form, a child form and a process definition. When there is an insert/delete into child form a trigger is raised and the process task gets called. The process task does whatever it needs to do on the target system. This is all fine. However, after the task completes, lets say successfully, I want to send out an email to the user saying, for example, group 1 has been added to you or just got deleted.
    I am not able to figure out how to get that last operation and child form data. I am sure you came across this and if so please let me know how to do this.
    Thanks

    So, Can I add a similar process task with the same exact condition one more time? I thought I couldn't use the same condition again. For example, when a group is deleted can I use the process data->child data->group Id with old value check box checked on another process task?

  • Q - How to program the min/max values of an intensity graph

    Hi LabViewers,
    I'm looking for a way to program the min/max Z values of an intensity
    graph for image display properly, but unable to figure it out so far.
    Any idea?
    Chengye

    Right click the graph's control on the block diagram and create a property node.  Right click the node and Change all to Write.  RIght click the node again and select from Properties either the combined ZScale->Range->All elements  -or- you can individually define 2 property nodes for Max and Min (also under Zscale->Range).
    Message Edited by Jonnie 5 on 12-14-2005 03:07 PM
    2006 Ultimate LabVIEW G-eek.

  • How to get the exact Height and width of the text in TextLayout Framework

    Hello fellow developers,
    I start working with TLF when there is three different SWC's Now I am working with Single SWC with flex 4 and lot of things are changed like
    I use calculateHeight(),calculateWidth()  now these methods are not available.
    Please if anyone know the replacement of these methods then Let me know.
    thanks

    If the text exceeds the container, which can happen in a scrollable container where you have to scroll to see some of the text, then the values getContentBounds returns are estimated values. This is because we don't want to force the text to recompose all the way to the end of a very long TextFlow in order to return a value. However, if you want to get the exact amount, and don't mind taking the time to recompose, call textFlow.flowComposer.composeToPosition(), before calling getContentBounds. This forces all the text to recompose to the end, and then getContentBounds will return the fully calculated value instead of estimating.

  • SDK : how to get the server adress and port ?

    Almost everything is in the title, I'm look for code to get the server URL and port where the ME is running ;o)
    There should be some standard API I guess.
    Thanks
    Regards

    Hi,
    In the code that I write I usually have access to the HTTP Request Object.
    String serverName = request.getServerName();
    String serverPort = request.getServerPort();
    Then I just do a compare on the returned value to see if I am on our Test or Production server.
    if(request.getServerName().indexOf("prodservername") >= 0)
      // PRODUCTION CODE HERE
    else
      // TEST CODE HERE
    Hope this helps,
    Mike

Maybe you are looking for

  • Open File dialog in 1.1.0.21

    This is an old issue which I thought was supposed to be resolved in 1.1, but whenever you go to the open file dialog, it still always starts in the installation directory. It does not remember the last directory used and I cannot find anything in the

  • Remote startup and shutdown of of PXIe controller running Labview RT (WoL)

    I would like to be able to remotely start up and shut down a PXIe-8133/PXIe-8130 controller remotely over the LAN.   I can see that the hardware specs for the PXIe-8133 supports wake on lan (WoL), but I'm not sure about the 8130 (although it seems to

  • Cheque Incoming payment out of range error

    Hi All There is a transaction of incoming payment on 01-12-2008 (which is belongs to last financial year) of which 'Cheque' type.  while adding the document the system throws a message the date is out of range.  what could be the problem? SV Reddy

  • Safari cannot recognize Pdf files

    Safari  6.0.1 OSX 10.8.2 I have seen many posts relative to Safari being able to open Pdfs, but my issue is different. Safari can open the document, but it is not able to recognize the document as pdf and does not render it and just shows the raw dat

  • Importing 9i dump file into 10g database

    Hello guys, i know that 9i import is incompatible with 10g datapump.I want to know how i can move the data from my production database(9i) to the new site(10g) without much hassle. I don't want to use upgrade because not all objects in 9i is needed i