Wrapping my head around PIVOT - Arggggg

Ok, I am stumped. What I want seems so simple to me....
======= Table Def
CREATE TABLE "TI" (
"SNUM" NUMBER,
"SYMBOL" VARCHAR2(30),
"OPEN" NUMBER(15, 5),
"LOW" NUMBER(15, 5),
"HIGH" NUMBER(15, 5),
"CLOSE" NUMBER(15, 5),
"ADJ_CLOSE" NUMBER(15, 5),
"VOLUME" NUMBER(15, 5),
"CHANGE_PCT" NUMBER(15, 5),
"CHANGE_AMT" NUMBER(15, 5),
"TIMESTAMP" TIMESTAMP(9) DEFAULT systimestamp ,
"TRADE_DATE" DATE,
"DATA_SOURCE" NUMBER)
============ data
insert into TI (6975 ,'VT', 48.2,48.11, 48.41,48.23,48.23,200500,.009,.43,'01-JAN-11','08.32.57.366984000 PM','03-JAN-11',2)
insert into TI (6995,' AGG',105.4,105.3,105.68,105.63,105.63,739700,-.00113,-.12,'31-JAN-11 08.33.18.137327000 PM','03-JAN-11',2)
insert into TI(7015,'SPY',126.71,125.7,127.6,127.05,127.05,138725200,.01034,1.3,'31-JAN-11 08.33.34.708030000 PM','03-JAN-11',2)
So as you can see these are all on the same date. We currently collect three indices every day, but a user with the click of a mouse could add another or take one away.
What I am trying to do is get output gives a date and the indices contained in a given day and their adj_close as a single return value from a query.
I have spent the day trying to wrap my head around PIVOT or LISTAGG but just can't seem to get a grasp of the damn thing. All the examples I have seen incluse sums and such and I need, nor in fact do I want anything summed. This would seem to come down to grouping by the trade_date and that where something is just not making sense.
More then an answer ( although an answer would be very helpful :) ) It would be great if someone could simply lay out how this is supposed to work. Uhm did I say an answer would be helpful <big cheesy smile >
Thanks in advance...

Hi,
Thanks for posting the CREATE TABLE and INSERT statements. Please test any code before you post it; there seem to be a lot of mistakes in those 4 statements. Don't forget to post the results you want from the sample data, and your version of Oracle.
One thing that is common to all forms of pivoting or string aggregation is that you need to know, for each row of input, to which row and which column(s) (or position(s)) of output it corresponds. Sometimes one or both of these are already in the data, but sometimes they have to be derived from the data. I'll assume you have one of each: that trade_date indicates the output row, and that the column you called timestamp (but which I'll call tmstmp, since timestamp isn't a good column name) can be used to tell the output position: the earliestt tmstmp goes on the left, the 2nd lowest tmstmp goes next, the 3rd lowest tmptmp goes next, and so on. We can use the analytic ROW_NUMBER function to assing consectuive numbers (1 for lowest, 2 for 2nd lowest, 3 for 3rd lowest, and so on) to the different tmstmps for each trade_date. I'll assume you don't know how many of these there will be on any given trade_date, and there may be different numbers of them on different trade_dates in the same output. I'll assume you're using Oracle 10.
If you have an unknown number of items, then string aggregation (concatenating all the values into one big sting column) is a lot easier and more robust than pivoting, so let's do it that way.
Here's one way to do string aggregation:
WITH     got_c_num     AS
     SELECT     adj_close
     ,     trade_date
     ,     ROW_NUMBER () OVER ( PARTITION BY  trade_date
                         ORDER BY        tmstmp
                       )     AS c_num
     FROM     ti
--     WHERE     ...     -- if you need any filtering, put it here
SELECT       trade_date
,       REPLACE ( SYS_CONNECT_BY_PATH ( TO_CHAR (adj_close, '999990.000')
            )          AS indices
FROM       got_c_num
WHERE       CONNECT_BY_ISLEAF     = 1
START WITH     c_num          = 1
CONNECT BY     c_num          = PRIOR c_num + 1
     AND     trade_date     = PRIOR trade_date
ORDER BY  trade_date
;Output from your sample data:
TRADE_DAT INDICES
03-JAN-11       48.230     105.630     127.050CONNECT BY is used for parent-child realtionships of variable length within one table. Here, we have assigned c_num to be 1 for the first input row for each trade_date, 2 for the next, and so on. In the CONNECT BY uery above, we're saying that every parent-child-grandchild-... chain will start with a row numbered c_num=1, and that a row will be considered the child of another row if its c_num is 1 higher, and their trade_dates are the same. (That's what the START WITH and CONNECT BY clauses are doing.)
SYS_CONNECT_BY_PATH gives a delimited list of items, starting from the root (the item with no parent, c_num=1) and showing the lineage down to each item in the original table that is descendedd from some root. That means we get 3 rows of output in this case: one showing just c_num=1, another with that same c_num=1 and c_num=2. and finally one with all 3 c_nums. We're only interested in the last one, the onme with no child, so the WHERE clause discards the others.
By using TO_CHAR in SYS_CONNECT_BY_PATH, we get items that are padded to the same length. That way, when they are displayed, they will appear to line up in neat columns. SYS_CONNECT_BY_PATH reuires that you delimit the output items with some string that cannot possibly occur in the items themselves. I chose '/', but, since we don't want to see those '/'s, I used REPLACE to get rid of them once we were finished doing the SYS_CONNECT_BY_PATH.

Similar Messages

  • I can't seem to wrap my head around resizing/resampling and what is the correct way of doing it (CS5)

    i know this is probably fairly basic but it's escaping my grasp at the moment.  for whatever reason my teacher never really went over this other than to say 300dpi was what you want for the best quality prints, so i've always just sort of worked with that in mind and never gave much consideration to "re-sampling" or what it was necessarily, the box was just always checked.  im not sure how much, or if, i've been screwing myself all this time, and i know this isn't THAT difficult so any advice would be appreciated.  and i apologize if this has been gone over to death, but i wanted to use an example to help (hopefully) understand this better.
    oh, and most of my work i display on the internet with the idea that it will in the future be printed, or with the notion that it can at least be printed.  i've heard for web all you need is 72dpi, but since i expect it to be printed i just do 300dpi and save it normally.  is this a bad move on my part and am i missing something by not saving it "for web and devices"?
    example:
    so i have an image i downloaded from the internet.  as you can see it's at 72DPI and around 12.7x17.7in.
    let's say i want to enlarge it to an even 13in and increase the resolution to 300DPI.
    i'm confused as to when i want to uncheck resample.  since it locks the pixels, if i increase the resolution the image gets smaller, and vice versa.  i'm not sure i grasp when it's beneficial to have resample unchecked.
    i feel really stupid, because i know all of this is pretty noobish but we hardly touched on this and the option of saving for web & devices (not at all) in my design class.  thanks for any help.

    just to clarify the point of the example i'm using...
    let's say i'm going to use part of the knight as a composite on a larger canvas.  i'm basically wanting the image to be as "optimal" as it can be, and large enough so that it can be further resized larger (if need be) without seriously compromising the quality.  i know that it's easier make a larger image bigger than it is a smaller image.
    i guess this way of working helps me keep the number of variables down.  like if i take the helmet and put it on the image of a woman in bikini.  even if the images are different sizes i should be able to scale them until they are proportional, and then if there are any issues i know that it probably has something to do with the original source and not me.
    does any of that make sense?
    honestly, i'm not sure if my way of thinking is ill thought or not.  i'm assuming if i have an image made up of several other images, all at varying resolutions, the final product will be a mess.

  • Attempts to wrap my head around printing and color management.

    So, I've been meaning to get (more) serious about printing my shots. It's the summer and I now have some time.
    I know I've got the first piece of the puzzle in place. I have an i1 Display 2 that I use to calibrate my monitor - my MB + one of 2 Dells using either or TN or P-MVA panel. I try to use the latter more.
    I've viewed the image with different monitors and lowered the brightness when 'soft proofing' with Canon's profile. It's the best I can do being that I don't own a spectrometer.
    Anyway the result on my screen was so incredibly different. The black was grey. I lost shadow detail. And it just looked flat. I tweaked it a bit but it didn't help.
    I decided to test print using the Canon Photo Plus Glossy paper I had. I set the ColorSync Profile box to the profile I soft proofed with. The result was horrible!!!! Incredibly dark and ugly. It however wasn't grey or very flat - though it was so dark.
    I tried again with the colorsync profile set to system managed. This produced a result darker than the screen, but not grey like the profile. Sort of an average between the screen and profile. Much better but still not great.
    Then I ran out of paper and couldn't try anything else.
    So here's the technical info if it matters:
    I'm using a canon ip5200 with 3 fresh inks. The other 2 are fairly recent and not used too much.
    The paper was Canon Photo paper plus glossy
    The photo was a sports shot with a heavy dark vignette I think a more even shot would be easier to work with. However, the dark vignette with blonde flying hair looked great. (Who says sports can't be artistic?- I love the vignette to for some shots!)
    So what exactly is the ColorSync Profile menu in the print window for?
    What am I doing wrong?
    PS: Sorry if this is a repeat, but the search function is down.

    Sorry to be the bearer of bad news but there are some seriously weird stuff going on with printing with Aperture and 10.5 I would not have believed it had a number of my clients and friends not experienced the same kind of issues that I personally walked through and witnessed.
    I can give some general advise in terms of helping to resolve your issues. By all means update to 10.5.4 do a repair permissions on your drive, make sure that you reinstall the latest greatest printer drivers for Leopard downloaded from Canon, and wave some chicken bones over your system.
    You may also want to trash your Aperture prefs and Printer presets and start from scratch. (if you do not know how to do this hit me back)
    Then give it another try - make sure that you turn off color mgt in the printer prefs dialog, select the appropriate paper and then select the corresponding profile in the aperture print dialog. (Have heard reports that if you do not turn the color mgt off in the driver the option becomes unavailable after you select the paper profile in Aperture but does not turn it off - cannot confirm)
    Hope this helps.
    RB

  • Trying to wrap my head around synchronized, wait, notify

    Hi There,
    I've been researching on how to make my midlet repeat cpu-intensive tasks for long periods of time. I found that if I put the big jobs in separate threads, that works fine. However, I'm at a point now where I need my "worker threads" to be able to do a big job, check to see if they need to keep going, then repeat. It seems that synchronized, wait, and notify are the way to do that. But I'm new to this concept.
    Apparently you can only use synchronized to create a spinlock between objects. So I guess that I need to define a new class, that starts its own thread, and has a method inside that thread that is synchronized?
    If that is true, then can my midlet call notify() on that? How does my midlet become a monitor?
    What does notify really do? Does it make the thread synch up state with the midlet globals? How can I get updated information to the thread?
    These things will help me get started.
    Thanks,
    theotherldso

    I answered my own question. I solved the problem by creating my own runnable class with some methods to control the thread. It works great, it's kind of like having my own main() that is controlled from my midlet.

  • I am no musician, but have owned an iMac now for around four years. During that time I have had Garageband installed. I have dipped in and out very occasionally as I would like nothing more than to be able to get my head around it just for my own amusemen

    I am no musician, but have owned an iMac now for around four years. During that time I have had Garageband installed. I have dipped in and out very occasionally as I would like nothing more than to be able to get my head around it just for my own amusement really. I would at least like to be able to record my electric guitar with loops and tracks etc, just try to be a bit creative and see what comes out. The problem that I have is that perhaps its me, but every time I try to get to grips with this software, I just can't seem to get my head around it, even to begin to do something. I have now recently downloaded 10.0.2 which is confusing in itself, as, as far as I can ascertain that is actually version 11, but I'm not even sure about that. I have also recently purchased a Rocksmith RealTone Cable to connect my guitar. I can sometimes get a sound come out, but nothing to brilliant. And every time I try to set something up, it just doesn't seem to work out. I end up hitting buttons and controls in the simple hope that I may hit the correct control in order to get some sort of result. But I'm kind of fumbling in the dark with this. I have trawled the Internet just trying to find either a good manual or video tutorials for absolute beginners, but there just simply doesn't seem to be anything of that nature out there and what there is appears always to be very sketchy and not particularly detailed in explaining anything properly, and so I always find myself seemingly jumping in with both feet and just struggling to try and find a foothold with this on how to really begin. It is so frustrating as I can see the fantastic potential of this software, but just can't understand how to use it properly. If there is anyone out there who may be able to offer me some advice with this, I would be most grateful indeed... Many Thanks.

    I have now recently downloaded 10.0.2 which is confusing in itself, as, as far as I can ascertain that is actually version 11, but I'm not even sure about that.
    Version 10.0.2 is the newest version and the successor to GarageBand '11 (version 6.0.5).
    The '11 is referring to the iLife '11 suit of multimedia application - the older GarageBand was a part of this bundle.
    Have a look at Edgar's graphical enhanced manuals, the explain very detailed how things work and why. You can buy them as iBooks from the iBook store or directly from the page:
    http://DingDingMusic.com/Manuals/

  • New itunes can't get my head around it

    Hello.
    Recently downloaded the latest version of itunes and I honestly have tried to get my head around it with plenty of good will but it just doesn't work for me. So i was wondering am I the only one or are there others? would love to hear about what you like and what you don't like here is my comments:
    genius playlist:
    why can't i see full list of previous songs played? if I would like to hear a specific previous song in the list I cannot just click it
    why can't i access song sub-menu? old itunes you could right click on the song and search for the file location for example?
    why do I need seperate windows to open when opening specific items such as downloads or genius why can't they just feature in the main screen?
    but my biggest gripe with it  is that it just generally feels overcroweded. the previous version was so clear and easy on the eye with enough information to know what was listed but not too much to make you lose focus on what you are after. This one offers so much information on everything that I cannot seem to focus any more (maybe not bright enough )
    but seriously as an example of overcrowding, it now lists all the TV series I have previously purchased and removed as already watched. Although no longer on my main hard drive it comes up as available through iclouds. I specifically stored them in a seperate hard drive to not overcrowed my itunes now they are back. and the fact that you can select to only show the non viewed TV episodes doesn't help as it shows series I have bought but haven't downloaded yet .
    am I the only one and starting to become a grumpy old man? should I just accept and adapt? looking forward to hear other peoples thoughts

    I love the new version of Grid view but some of the other changes feel like they still need some fine tuning. And I miss cover flow even if I didn't use it that often...
    You can restore much of the look & feel of the previous version with these shortcuts:
    Ctrl-B to turn on the menu bar.
    Ctrl-S to turn on the sidebar (your device should be listed here as before).
    Ctrl-/ to turn on the status bar.
    Click the magnifying glass top right and untick Search Entire Library to restore the old search behaviour.
    Use View > Hide <Media Kind> in the cloud or Edit > Preferences > Store and untick Show iTunes in the cloud purchases to hide the cloud items. The second method eliminates the cloud status column (but perhaps it does more)
    If you want to roll back to iTunes 10.7 first download a copy of the 32 bit installer or 64 bit installer as appropriate, uninstall iTunes and suppporting software, i.e. Apple Application Support & Apple Mobile Device Support. Reboot. Restore the pre-upgrade version of your library database as per the diagram below, then install iTunes 10.7.
    See iTunes Folder Watch for a tool to scan the media folder and catch up with any changes made since the backup file was created.
    tt2

  • How do i take a image of a wine glass and wrap a image around it in indesign cs6

    How do i take and image of a wine glass and wrap another image around it!

    InDesign isn't the correct application for such a manipulation.
    If the "image of a wine glass" is a 2-dimensional image, you may be able to create the illusion of something wrapped around it in Photoshop, but there won't be any automatic solutions. Fundamentally, what you're proposing is a function of 3-D modeling.

  • How to wrap the heading text in alv.

    HI all,
          I need help, how to wrap the heading text in alv.
    can any help ... plz..
    Advanced Thanks
    Regards
    GUhapriyan

    Hello GuhaPriyan,
    I assume that you're referring to the ALV Grid's title. The maximum length for this title is 70 characters and this would generally fit in the one line.
    Are you intending to wrap it because you purposefully want the text to come in two lines? In that case, I'm not sure that it's possible.
    But otherwise, there's an option in the Layout called SMALLTITLE. You can set this attribute so that the title would be displayed in a amaller font and hopefully, all of your text shows up on the screen.
    Regards,
    Anand Mandalika.

  • Fixed header for Pivot Table

    Is there any way to show the fixed row header for Pivot Table. Currently its showing on hover.
    Thanks
    Suneesh

    Hi,
    I also have this problem. My view is using 3 EO, my third tables have multiple rows and I want these rows displayed as columns. So I'm using a pivot table to achieve this. I then only have one column in the "data" section of the pivot and all other data is to its left. I only see the column headers on hovering over the column and tha6t just wont suffice. Is there any way of modifying the width aswell?

  • Getting my head around DocumentListener and how inner classes work

    So I'm trying to get my first Swing GUI up and running and I cannot get my head around the DocumentListener.
    I have a JTextArea element called textArea which has the following code for it's listener:
    public class Gui extends JFrame {
        public Gui() {
            // Add the Text area
            JTextArea textArea = new JTextArea(textDoc);
            add(scrollPane, BorderLayout.CENTER);
            textArea.getDocument().addDocumentListener(new DocumentListener() {
                public void changeUpdate(DocumentEvent e) {
                public void insertUpdate(DocumentEvent e) {
                    saveText();
                public void removeUpdate(DocumentEvent e) {
                public void changedUpdate(DocumentEvent e) {
                    throw new UnsupportedOperationException("Not supported yet.");
        public void saveText() {
            System.out.println("saving");
    }Now of course this will not work. The method saveText() is in the parent class. So how do I invoke this method???
    Instead of calling the saveText() method I could interact with the variables of the parent class so why can't I invoke the method?

    OllieL wrote:
    public void insertUpdate(DocumentEvent e) {
    saveText();
    }Now of course this will not work. The method saveText() is in the parent class. So how do I invoke this method???Really? What happened when you tried? What does "will not work" mean? A compile error?
    Anyway, if there actually were a conflict (there isn't here, that's not why it's not working) you can always qualify the member further:
    //for instance member
    Gui.this.saveText();
    //for static member
    Gui.otherMethod();

  • Table heading in pivot view

    Hi All
    I am trying to show table heading in pivot view but failed. Please help me on this
    I know that can achieve in table view but looking for a solution in pivot view.
    What I am lookinf for is: Pivot View
    Rows ---------Measures----------
    X Y (Table Heading)
    col1 col2 col3 col4 col5 col6 (column names)
    --- --- --- --- ---- ---- (data)
    Thnaks in advance!

    Ok, for example take two columns product and revenue. Consider they are 10 products.
    What I have to display in report is 9 products with revenue and total revenue of those 9 products and then the 10th product and revenue and finally the grand total.
    Product---Revenue
    1---35
    2---45
    9---60
    Total---140
    10---70
    Grand Total---210
    Which can be achieved the same in pivot view (using New calculated item)
    I also need to display the table headings, there I stuck with.

  • Wrapping vector label around a photographed bottle

    I've designed a label for a soda bottle and now want to wrap it around a photograph of a bottle.  I actually mocked up the label and conducted a photoshoot, but now that I'm looking at it, the colors just don't match (see examples below) - which is why I want to utilize the vector label and slap it over the photograph.
    Since I've gone ahead and mocked up the bottle with the  printed wrapper adhered to it, I want the positioning of the vector label to match up to the photographed label as closely as possible - because you can't get any  better perspective than reality.  The bottle was shot as dead on to center as possible, there is only an inkling of a vertical bulge.
    This is the screenshot of the entire vector label that was printed and used on the photograph above.  The label overlaps itself by only a several militers for gluing.
    So how do I go about wrapping this vector around the photographed bottle in order for it to match?
    I've already tried freestyling with Transform > Warp in PS - but its painstakingly hit or miss.  I thought about mapping the vector label around a 3D cylinder of the same diamter of the photographed bottle and placing it over the bottle in PS.  Any other suggestions?
    In the future, would taping a grid onto my bottle then photographing and aligning a digital version of the same grid & label be the best workflow?  Such as shown in this tutorial
    Thanks!

    Hi,
    In the Layers panel of the 3D layer, you can revel the layer effects (which also has 3D texture maps) by clicking on the triangle at the right. From here, double clicking the name of the texture will open it. Alternatively, you can open the various texture maps inside the 3D panel, by first choosing the material to edit then navigating into the pop-up menus of the properties area.
    I see that I actually scaled your artwork beyond the bounds of the cylinder edges to quickly get the artwork centrally placed. It would be better to start with your AI artwork placed into a new document and generate a Cylinder from that layer.
    Once you get that created, place it into your image document and using the 3D camera, change the zoom level to affect the perspective (I over zoomed to 300 mm) while at the same time walking the camera back to keep it in frame. Once you have the perspective looking close, use the 3D axis widget with the cylindar mesh selcted, to constrain scale the cylinder to fit your image.
    Hopefully this helps. It would be much better to see an animated walk thru but I'm not really setup for that at the moment.
    regards,
    steve

  • How can i wrap a tag around content?

    how can i wrap a tag around content? for example if i have a block of text, in previous versions of dw i could just select a block of text and click the p tag in the file menu and dw would put opening and closing tags. now in creative cloud version it puts the tags after the block of text. is there a setting to adjust this? thanks

    if i have 10 list items is this the easiest way to wrap the li tags around them? before you could simple select the text and highlight it and click the li in the toolbar. thanks murray

  • Photoshop CC / 3D - Wrapping a graphic around a cylinder without repeating.

    I'm trying to wrap a label around a 3D bottle by inserting the label as a diffuse texture. I am able to position and scale the label proportionately, however instead of wrapping around the bottle once, it's repeating twice. I've tried fooling with the UV Properties with no success. Can anyone tell me how to successfully wrap a graphic around a model once without repeating?

    You know a lot more about 3D then I do.  You wrote that you were wrapping you label around a cylinder. So that is what I did. I know nothing about how to use extrusions like you do. I have just played a little with Adobe preset meshes like the wine bottle, cylinder and sphere.  Its easy to put label on cylinders or wrap the earth around a sphere or put a collage on a Christmas ball.  That is what  I did and I also created an opacity map.
    View screen captures in new tabs ans scale to actual size.

  • How to wrap an image around a mug in Photoshop CS5?

    I have tried many things like transform -> warp or tried to play with 3D but nothing gave me an effect like this image. Does anyone know a good tutorial or would like to explain to me how to wrap an image around a mug and make it look realistic like this?

    For Photoshop Elements
    Step A
    Select the Type Tool, type in your text
    .. then look at the top of the
    page
    You will see an arc with a T over it
    Click on that and you will be
    able to curve the text
    Step B
    There are 3 items to consider in order for this project to come out
    satisfactorily.
    A. The picture of the coffee mug needs to be properly
    sized, and enhanced
    B. Directions for the text above
    C. The picture for application to the mug needs to be
    configured so that its curvature conforms. I shall give you directions, but the
    values may require adjustment for your particular picture:
    Duplicate background layer, and shut off visibility by clicking on its eye
    icon
    Increase canvas size Image>resize>canvas
    size. Uncheck relative. Enter new values for width & height. Try 120% (+/-).
    You need more "real estate" for the next steps. The checkerboard pattern denotes
    transparency, which you want all around.
    Rotate picture. Image>rotate>layer, 90
    degrees right
    Filter>distort>spherize. Set mode to vertical only. Amount 100%
    Filter>distort>shear. Click center of control line, grab this center
    handle, and pull just a little to left
    Rotate picture back. Image>rotate>layer>90 degrees left
    Copy to clipboard, paste on picture of mug. Position and adjust size with
    move tool.
    Edit: Resolution of picture of mug and of picture to be applied should be about
    the same number. You can check this in Image>resize>picture size before you embark on
    above.

Maybe you are looking for