Another way for the UNION

I'm trying to get this result,

EQPID EVENTVAL 20120501 20120502 20120503 201204 201205
-------------------------------------------------------------------------------------------------------------------
MS - A1 21528 28386 18288 821295 908602 TKINQTY
MS - A1 21510 28359 18270 820470 907321 TKOUTQTY
MS - B1 21090 17990 15750 467922 557239 TKINQTY
MS - B1 21080 17982 15735 467495 556730 TKOUTQTY
MS - C1 35548 23848 26082 914351 1013655 TKINQTY
MS - C1 35533 23826 26058 913727 1012888 TKOUTQTY
MS - D1 22680 17568 15030 514467 494510 TKINQTY
MS - D1 22660 17565 15021 513955 493857 TKOUTQTY
MS - E1 18450 20916 20754 429057 490732 TKINQTY
MS - E1 18436 20912 20739 428564 490188 TKOUTQTY
MS - F1 13968 14436 14670 440760 517343 TKINQTY
MS - F1 13949 14409 14657 440364 516870 TKOUTQTY
MS - G1 21060 21600 25240 573409 460286 TKINQTY
MS - G1 21057 21595 25237 573317 459888 TKOUTQTY
MS - H1 16452 19278 21456 510192 545201 TKINQTY
MS - H1 16452 19278 21456 510174 545174 TKOUTQTY
170776 164022 157270 4671453 4987568 TKINQTY
170677 163926 157173 4668066 4982916 TKOUTQTY
341453 327948 314443 9339519 9970484


in this table

CUTOFF_DATE EQPID TKINQTY TKOUTQTY
-------------------------------------------------------------------------
20120401 MS - A1 46566 46524
20120401 MS - B1 13734 13720
and so on...

Here is my code,

SELECT EQPID, «EVENTVAL' AS «EVENTVAL', SUM("20120501") AS '20120501', SUM("20120502") AS '20120502', SUM("20120503") AS '20120503', SUM("201204") "201204" AS, SUM("201205") "201205" AS
Of
(
SELECT EQPID, «EVENTVAL' AS «EVENTVAL', SUM("20120501") AS '20120501', SUM("20120502") AS '20120502', SUM("20120503") AS '20120503', SUM("201204") "201204" AS, SUM("201205") "201205" AS
Of
(
SELECT EQPID,
CASE
WHEN EQPID LIKE 'MS-% '.
THEN "TKINQTY".
END, LIKE "EVENTVAL."

CASE
WHEN CUTOFF_DATE = '20120501'
THEN SUM (QTY)
END, LIKE "20120501."

CASE
WHEN CUTOFF_DATE = '20120502'
THEN SUM (QTY)
END, LIKE "20120502."

CASE
WHEN CUTOFF_DATE = '20120503'
THEN SUM (QTY)
END, LIKE "20120503."

CASE
WHEN CUTOFF_DATE BETWEEN '20120401' AND '20120430'
THEN SUM (QTY)
END AS "201204."

CASE
WHEN CUTOFF_DATE BETWEEN '20120501' AND '20120530'
THEN SUM (QTY)
END AS "201205.

Of
(
SELECT CUTOFF_DATE, EQPID, SUM (TKINQTY) QTY.
OF DAILY_DATA
WHERE CUTOFF_DATE BETWEEN '20120401' AND '20120530'
AND EQPID LIKE 'MS-%'
CUTOFF_DATE GROUP, EQPID
ORDER BY CUTOFF_DATE, EQPID
)
EQPID GROUP, CUTOFF_DATE
)
EVENTVAL GROUP, EQPID
UNION
SELECT EQPID, 'EVENTVAL' AS 'EVENTVAL', SUM("20120501") AS '20120501', SUM("20120502") AS '20120502', SUM("20120503") AS "20120503", SUM("201204") AS "201204', SUM("201205") AS"201205 '"
Of
(
SELECT EQPID,
CASE
WHEN EQPID LIKE 'MS-% '.
THEN "TKOUTQTY".
END, LIKE "EVENTVAL."

CASE
WHEN CUTOFF_DATE = '20120501'
THEN SUM (QTYO)
END, LIKE "20120501."

CASE
WHEN CUTOFF_DATE = '20120502'
THEN SUM (QTYO)
END, LIKE "20120502."

CASE
WHEN CUTOFF_DATE = '20120503'
THEN SUM (QTYO)
END, LIKE "20120503."

CASE
WHEN CUTOFF_DATE BETWEEN '20120401' AND '20120430'
THEN SUM (QTYO)
END AS "201204."

CASE
WHEN CUTOFF_DATE BETWEEN '20120501' AND '20120530'
THEN SUM (QTYO)
END AS "201205.

Of
(
SELECT CUTOFF_DATE, EQPID, SUM (TKOUTQTY) QTYO
OF DAILY_DATA
WHERE CUTOFF_DATE BETWEEN '20120401' AND '20120530'
AND EQPID LIKE 'MS-%'
CUTOFF_DATE GROUP, EQPID
ORDER BY CUTOFF_DATE, EQPID
)
EQPID GROUP, CUTOFF_DATE
)
EVENTVAL GROUP, EQPID
)
GROUP BY ROLLUP (EVENTVAL, EQPID)
ORDER OF EQPID, EVENTVAL


It seems to be so long, and I try to avoid the UNION...
Is there an alternative way to achieve the same result without the help of the union?

Thank you

Estelle =)

Published by: 1004902 on May 8, 2013 17:52

Published by: 1004902 on May 8, 2013 17:59

Hello

Welcome to the forum!

1004902 wrote:
I'm trying to get this result,

EQPID EVENTVAL 20120501 20120502 20120503 201204 201205
-------------------------------------------------------------------------------------------------------------------


MS - A1 21528 28386 18288 821295 908602 TKINQTY
MS - A1 21510 28359 18270 820470 907321 TKOUTQTY
...
in this table

CUTOFF_DATE EQPID TKINQTY TKOUTQTY
-------------------------------------------------------------------------
20120401 MS - A1 46566 46524
20120401 MS - B1 13734 13720
and so on...

Every time you ave a problem, CREATE TABLE post and instructions INSERT for your sample data and the results you want from this data.
Explain how you get these results from these data.
Always say what Oracle version you have (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}

It seems that the UNION may be replaced by a cross join, or SELECT... UNPIVOT depending on what version of Oracle you are running.

Published by: Frank Kulash on May 8, 2013 21:52

You may want something like this:

WITH    cntr    AS
(
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL     <= 2
)
,     got_eventval     AS
(
     SELECT       d.cutoff_date
     ,        d.eqpid
     ,       CASE
                WHEN  c.n = 1  THEN  'TKINQTY'
                                   ELSE  'TKOUTQTY'
            END     AS eventval
     ,       CASE
                WHEN  c.n = 1  THEN  d.tkinqty
                                   ELSE  d.tkoutqty
            END     AS qty
     FROM         daily_data  d
     CROSS JOIN  cntr     c
     WHERE    cutoff_date BETWEEN '20120401'
                     AND     '20120530'
        AND       eqpid           LIKE 'MS-%'
)
SELECT       eqpid, eventval
,       SUM (CASE WHEN cutoff_date = '20120501'  THEN qty END)  AS "20120501"
,       SUM (CASE WHEN cutoff_date = '20120502'  THEN qty END)  AS "20120502"
,       SUM (CASE WHEN cutoff_date = '20120503'  THEN qty END)  AS "20120503"
,       SUM (CASE WHEN cutoff_date LIKE '201204' THEN qty END)  AS "201204"
,       SUM (CASE WHEN cutoff_date LIKE '201205' THEN qty END)  AS "201205"
FROM       got_eventval
GROUP BY  eqpid, eventval
ORDER BY  eqpid, eventval
;

Of coursel, I can't test it until you post the sample data.

Storage of the information on the dates in a column VARCHAR2 is a very bad idea. The columns DATE to the date information.

Tags: Database

Similar Questions

  • Help please on startup. Way for the app to identify himself.

    BB Storm JDE 4.7.0

    My goal is to create an application that can take an icon and a URL and create a home screen icon when you click it, it will open a web page (web link or launcher). Allows to call the application that makes the shortcuts of the 'Manager' application for convenience.

    The way I thought to do it now, is it. First of all, let me qualify it as an overly simplified version... the real app is more complex.

    OK, there is initially a model application that has another point of entry and start, it puts in place its icon and the name (read in a persistent store)

    .. .and also the URL to pass. It is all stored in the home screen so it has a unique name, a unique icon and when you click top of the homescreen will go to a single URL.

    Now, the tricky part. Y at - it a way for the software maker to assign a unique ID to the app so that when it starts it can understand of this ID

    the set of data to read from the persistent store?

    The idea would be to use createNewModule and give it its new name and icon before you save it using CodeModuleManager.saveNewModule ().

    In theory it should save it in a new module.

    So, my questions...

    1 I use createNewModule and saveNewModule after changing the name and the icon using HomeScreen, if the type of access point to the choice of starting. In general, which is put there as HomeScreen changes are usually not saved after reset.

    2. the code independent sign of the icon and the name? I would like to invite createNewModule a separate .cod file. It is also the reason why I didn't just change the table .cod and add strings for the icon names, URL, etc. in the table itself (would make the signature invalid code... I already tried this :-)

    3. If what I propose above work and I have to do the other thing entry point, so I'll need each app so it starts up and understand what icon and the name is, along with the URL. Is it possible to attach a unique id for the application on the creation?... so the 'Manager' app that can store in the store persistent as a key.

    and the remaining code can also determine it's unique ID at run time to get his key also. ??? Note that I do not have another way, which is more complex, so I prefer this way.

    Thanks in advance. Please read this before answering. No laurels to repeat what I say, but Bravo to everyone who adds something new... or can confirm with certainty or repudiate for sure something I said above.

    Thank you

    -Donald

    OK then, that's what I discovered.

    You cannot use createNewModule with an array of bytes to an application twice, calling same HomeScreen to assign a different name and an icon.

    There will only be one version, and if you search his name by any other means than by home screen, it will use its name .cod and print that.

    So, my opinion is that you cannot create several shortcuts to anything if you go around signing .cod files. It is possible. However, you then run on the problem that if RIM changes their signature info, all of a sudden, your code does no more work. either it is not worth.

    The free app out there is really the only way to do that is to create a set number of .cod files called whatever (well weblink1 6) and then you assign the URL and icon through the persistent store and who should do... each of these icons, in turn, can be set to the shortcuts. It just limits you to a defined number of URLS that can be done by the non-programmer.

    I had hoped to provide an application that could provide any. It is not possible. RIM could do if :-)

    I'm closing this now, because I know I can't write this App... because even once, I ran into the dreaded RIM API limitation. It is 4 good apps I had to zero because of the api didn't exist do not.

    It seems that only very simple apps or those who do not use specialized equipment are the only ones who can be written. IPhone will win if this is not changed soon.

    -Donald

  • BlackBerry smartphones is a way for the storm to "separate email accounts? '

    Forum,

    Is there a way for the Blackberry Storm to 'split' emails to 2 different accounts?  I have a corporate email account (MS Exchange) and a Yahoo! account.  Emails of these accounts appear in the Messages.  Is it possible to separate them so that I can view the emails in a view/account, Yahoo! mail in a different view/account?

    I guess it would be a type of client software for Blackberry email... dunno.

    Thanks in advance!

    Joe

    The alternatives will have to use an app of the add-on for the storm to create an icon that displays only the BES-based emails. See http://www.getempower.com/Empower_BES_MailBox.php for more information (I tried the free trial version and it worked great). The BES configuration method is discussed at http://www.blackberry.com/btsc/search.do?cmd=displayKC&docType=kc&externalId=KB15003&sliceId=SAL_Pub..., but we have yet to try this one. Another alternative is to use modules for non - BES mail... GMAIL offers an add-on which manages all GMAIL, bypassing BIS entirely... I don't know if other e-mail providers have something similar.

    I'm currently testing a configuration where I use BIS to get my company email, BES to OTA sync my company calendar and contacts, GMAIL of add-on application to handle this, and BIS to manage what other email accounts. I no longer watch the main 'Messages' box at all.

  • When firefox load it also load another tab for the search engine. How can I remove this where it will load only my start page?

    When firefox load it also load another tab for the search engine. How can I remove this where it will load only my start page?

    You can check the setting of the home page and make sure that it doesn't have a leak ' |'.

    Firefox supports several home pages separated by ' |' symbol.

  • save an image in an image file and reloaded on another computer for the image processing

    Hello

    Can I save the image to an image file and then reload the file on another computer for the image processing? What type of image format should I save for it? Is there any loss of image if I do this? The machine with the camera sits in our lab, and I want to test the software on my own computer image processing. So can someone give some good ideas on this. Thank you

    Jane

    I assume you have the module development VDM and vision acquisition software going TO on your computer.

    So just use playback IMAQ and IMAQ save functions. BMP, png are good for losless save unlike jpg and jpeg2000.

    Hope this helps

  • Is there a way for the secret video files to the sansa fuze using QUICK MEDIA CONVERTER?

    Is there a way for the secret video files to the sansa fuze using QUICK MEDIA CONVERTER?

    Not really. The way final only ot add videos on the "rocket" is SMC. Rhapsody will do this also, but I don't know that its faster.

  • How to reassign another employee for the account and remove my name

    I'm no longer in the Department and should reassign them to another employee for the account and remove my name.  How can I do this?

    [Personal information deleted by Moderator]

    Team license links that can help

    -https://helpx.adobe.com/contact/creative-cloud-teams.html using the team

    -manage your account http://forums.adobe.com/thread/1460939?tstart=0 team

  • Good way for the centering of the effects in "Fly"?

    Hi all

    I'm trying to center the text in a caption section. Both fly in different areas of the stage. Is there a quick way to make sure they end up centered? So far I have snorkel it until I get the two elements centered, a painful process? Advice on how to do it quickly? Thank you

    Dan

    Or you can change the XML code for the effect. or use the workflow that I use: create a target with a vertical and a horizontal line that you can position exactly using the accordion to Transform. And then put the end point of the path in this cross.

    Hope you understand my explanation... Take a look at this blog, the film of the first example, where the maps are flying to the same location, using this approach:

    http://blog.lilybiri.com/reset-effects

    Lilybiri

  • Best way for the customer to download for a box?

    I do a total makeover in an existing site and switch from GoLive to DW.  We had a need for the client to display rapidly changing information in a box on the home page, since the client isn't real "techno" I tried an easy solution.  What I have on the old site is an image I linked to Google Docs: he is editing a document on Google Docs and saving it, the link of the image I always points to a single document.

    It works fine, but I wonder if there is a better way to accomplish the task.  I have shell access to my Web host, so I peut play around the coast host if necessary.

    Thanks - John

    Try this http://www.cushycms.com/

    I think this would work well for your needs.

  • is there a way for the old macbook to fix?

    Hello

    I have macbook pro late 2011 (MacBook Pro (15 inch, late 2011) - technical specifications). and I think that his (AMD Radeon HD 6770 M) graphics card is broken by my speculation.

    first. made of images on the broken screen. as shifted to the left and/or right to halfway, upward or down etc then it starts to fail when you turn on again. and keep restarting itself. I have double installed mac os and windows, the two shows the bios screen and restarts before os login screens appear.

    My question is if I send it in to apple repair is likely that it can be fixed? and if yes. So how much would it cost? by my calculation cost = map chart of spare + repair expenses.

    because I live in the countries of the third world, it is little difficult and costly to do international shipping. So, I want to be make sure if it is possible and within my portfolio.

    If I give it to local garage, there is more than 90% chance they will change/replace the parties and they say something like "it's broken. and cannot be resolved. You can sell me for $ 50"when I go there more late to take it.

    I saved my income year-round and sold my old laptop to get this macbook in 2012. and I can not just throw it away. Thank you.

    PS: Sorry for my bad English. English is not my mother tongue.

    You need to take it to an Apple store or an Apple authorized service provider. There is a program under repair for these models as detailed here: https://www.apple.com/support/macbookpro-videoissues/

    They will run a test to confirm the problem. If so, it produces a special authorization code, they use to order a replacement logic card, then they program with you for the Mac will get a maintenance free of charge.

    Use the Service option to find suppliers in your area here: https://locate.apple.com

  • Where can I buy another battery for the Camileo S10?

    Hello.
    I would like to know if is there some compatibility for our Camileo S10 batteries.
    Thank you.

    Hello!

    Have you contacted an authorized service provider? They can order all the original parts of Toshiba and perhaps for camcorders too. Just ask for it. :)

    And maybe you can find it on eBay of the batteries for the TV camera. Check it!

    Good bye

  • Another vote for the restoration of rendered support H.264 and WMV

    Hello!

    I like the new features that have been added to Adobe CC 2014.

    However, to remove the ability to make H.264 (MP4) or WMV is essentially the program useless for me.

    SOUL added to the workflow process is a huge waste of time.

    If anything, I think that new versions of the software Add would support other rendering formats, not Remove them?

    If you could add H.264 and WMV support, I would really appreciate it?

    Thank you.

    See this for an explanation of this change and for the workflow to recommend:

    using Adobe Media Encoder to create videos WMV, H.264 and MPEG-2 for After Effects

  • Another room for the heads side on different Master Pages?

    I prepare an updated book existing with about 40 chapters, and I added a head aside to add graphic markers in the margins.  I took a chapter, went to the page master and enlarged the flow of the text.  Then, I went to Format | PageLayout. ColumnLayout and clicked on "room for side heads.  I then imported the layouts and the properties of the Document (to pick up the room for the heads side) in the other chapters.  For the main text flows on the 'left' and 'Right' template, it works very well.

    However, it is ruin the flow of the text on the page 'First' master, that I use for my chapters.  Strangely, the head side seems correct, but the left margin moves in 1.75 ".   If I click on the first page and turn to the "House of Chiefs side" off, then turned it off it for the entire document.  Here's a screenshot:

    Before.JPG

    And here's after:

    After.JPG

    Any suggestions on how to fix this?

    Thank you!!!

    John

    www.controlgeek.NET

    Ah, you put me on the right track - I had to change my "Chapter title" paragraph format to "through all of the Collins and side heads" and that fixed it.

    Thank you!

    John

    www.controlgeek.NET

  • Satellite P50 - 13 - mPCIe or another way for eGPU A - C

    Hello
    As in the title - is it possible to add some eGPU? Or where can I find mPCIe?
    Y at - it an easy way to discover, or I have to unscrew half laptop?

    I found USB3.0 adapter but... I don't think not that laptop can see graphics card

    Kind regards!

    As in the title - is it possible to add some eGPU?

    Sorry mate, I can't give you advice but found interesting page:
    http://lab501.NET/EGPU-connecting-ex...ntation/all/1/

    Maybe it could be useful for you.

  • Monitor another layer for the events to change an effect

    Is it possible for an effect to listen an another layer change event and then react to this?

    Here's the situation: I have a plugin that has a setting of layer. This layer parameter points to a text layer. Now, I would have the effect to respond to a user who changes the contents of a text layer (TextDocument object). I guess I could somehow store the State of the layer and compare permanently for changes, but I feel in response to an event would be far better - if it is possible.

    Thank you

    Michael

    you do not receive a call from rendering when the text layer changes?

    in all cases, you can create an invisible param with an expression on the subject

    that links to the source on the text layer param. you change the

    Settings when the text is changed and will trigger a new rendering.

Maybe you are looking for

  • Toshiba 40TL900A - power led but nothing happens

    Hello I have a 18 month old Toshiba 40TL900A, wait a service legend in a few days, my problem is that he seemed to just shut down/locked. I have the Green led light on the front and it won't do anything else, even after unplugging for a few hours, wh

  • Qosmio G10 to the HD TV connection pointers

    Hi all I just got a flea market G10-100 which is forming the basis of my entertainment system.I understand the Q10 is able to process and the HD video out and have read the forums, trying to figure out how to connect the G10-100 to my HD TV. I'm afra

  • RN316 - Pack of broken - Silica Gel beads to the unit

    It never ends! I ordered a RN316 to replace my 6 Ultra. The unit arrived today and the pocket of silica gel opened its doors kind of packaging or shipping. These crazy pearls are inside the unit. Am I void my warranty if I open the machine to get out

  • My Windows Update does not run

    Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: whenever I click on Windows Update, it will not work. the icon appears in the lower right corner at run time, but when I click also which

  • Annoying beep

    After installing the recent updates, my computer started to emit a loud, annoying beep whenever it pops up a message. (i.e., print the completed task, do you want to save changes, etc..) I have disabled all sounds via the Control Panel, but that he d