I don't know how I can optimize this SQL

Dear ALL:
I don't know how I can optimize this SQL.
Is it possible to make a better SQL or PL/SQL?
Please let me know your good thought.
Thank you.
Sincerely,
===========================================================
(SELECT     A, B, C, SUM(D) as D, AVG(E) as E
FROM      T1, T2
WHERE     T1.timestamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
AND TO_DATE('01:00:00','HH24:MI:SS')
GROUP BY A, B, C
UNION ALL
(SELECT     A, B, C, SUM(D) as D, AVG(E) as E
FROM      T1, T2
WHERE     T1.timestamp BETWEEN TO_DATE('01:00:01','HH24:MI:SS')
AND TO_DATE('02:00:00','HH24:MI:SS')
GROUP BY A, B, C
UNION ALL
(SELECT     A, B, C, SUM(D) as D, AVG(E) as E
FROM      T1, T2
WHERE     T1.timestamp BETWEEN TO_DATE('02:00:01','HH24:MI:SS')
AND TO_DATE('03:00:00','HH24:MI:SS')
GROUP BY A, B, C
UNION ALL
(SELECT     A, B, C, SUM(D) as D, AVG(E) as E
FROM      T1, T2
WHERE     T1.timestamp BETWEEN TO_DATE('03:00:01','HH24:MI:SS')
AND TO_DATE('04:00:00','HH24:MI:SS')
GROUP BY A, B, C
ORDER BY A ASC, B ASC, C ASC
===========================================================

Dear Warren:
Actually, for this query, it takes a few second to complete the query.
But, I have to create several time period and I have to optimize the SQL.
Time period is 1 hour, 30 min, 15 min, 5 min.
That is,
===========================================================
WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
AND TO_DATE('01:00:00','HH24:MI:SS')
UNION ALL
WHERE T1.timestamp BETWEEN TO_DATE('23:00:01','HH24:MI:SS')
AND TO_DATE('24:00:00','HH24:MI:SS')
===========================================================
WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
AND TO_DATE('00:30:00','HH24:MI:SS')
UNION ALL
WHERE T1.timestamp BETWEEN TO_DATE('23:30:01','HH24:MI:SS')
AND TO_DATE('24:00:00','HH24:MI:SS')
===========================================================
WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
AND TO_DATE('00:15:00','HH24:MI:SS')
UNION ALL
WHERE T1.timestamp BETWEEN TO_DATE('23:45:01','HH24:MI:SS')
AND TO_DATE('24:00:00','HH24:MI:SS')
===========================================================
WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
AND TO_DATE('00:05:00','HH24:MI:SS')
UNION ALL
WHERE T1.timestamp BETWEEN TO_DATE('23:55:01','HH24:MI:SS')
AND TO_DATE('24:00:00','HH24:MI:SS')
===========================================================
Do you know how this SQL is optimized?
Thank you,

Similar Messages

  • Tables with more than one cell with a high number of rowspan (ej. 619). This cell can not be print in a page and it must be cut. But I don't know how  indesign can do this action.

    Tables with more than one cell with a high number of rowspan (ej. 619). This cell can not be print in a page and it must be cut. But I don’t know how  indesign can do this action.

    set the wake-on lan on the main computer
    The laptop's too far away from the router to be connected by ethernet. It's all wifi.
    No separate server app on the laptop, it's all samba
    The files are on a windows laptop and a hard drive hooked up to the windows laptop. The windows share server is pants, so I'd need some sort of third party server running. Maybe you weren't suggesting to use Samba to connect to the windows share though?
    I'm glad that you've all understood my ramblings and taken and interest, thanks The way I see it, I can't be the only netbook user these days looking for this kind of convenience, and I certainly won't be once chrome and moblin hit the market.
    Last edited by saft (2010-03-18 20:38:08)

  • How I can optimize this SQL query

    I require your help, I want to know how I can optimize this query
    SELECT
                    "F42119". "SDLITM" as "Code1"
                    "F42119". "SDAITM" as "Code2"
                    "F42119". "SDDSC1" as "Product"
                    "F42119". "SDMCU" as "Bodega"
                    Sum ("F42119". "SDSOQS" / 10000) as "Number",
                    Sum ("F42119". "SDUPRC" / 10000) as "preciou"
                    Sum ("F42119". "SDAEXP" / 100) as "Value",
                    Sum ("F42119". "SDUNCS" / 10000) as "CostoU"
                    Sum ("F42119". "SDECST" / 100) as "Cost"
                    "F4101". "IMSRP1" as "Division"
                    "F4101". "IMSRP2" as "classification",
                    "F4101". "IMSRP8" as "Brand"
                    "F4101". "IMSRP9" as "Aroma"
                    "F4101". "IMSRP0" as "Presentation"
                    "F42119". "SDDOC" as "Type",
                    "F42119". "SDDCT" as "Document",
                    "F42119". "SDUOM" as "Unit"
                    "F42119". "SDCRCD" as "currency"
                    "F0101". "ABAN8" as "ABAN8"
                    "F0101". "ABALPH" as "Customer"
                    "F0006". "MCRP22" as "Establishment"
    from          "PRODDTA". "F0101" "F0101"
                    "PRODDTA". "F42119" "F42119"
                    "PRODDTA". "F4101" "F4101"
                    "PRODDTA". "F0006" "F0006"
    where       "F42119". "SDAN8" = "F0101". "ABAN8"
      and         "F0006". "MCMCU" = "F42119". "SDMCU"
      and         "F4101". "IMITM" = "F42119". "SDITM"
      and         "F42119". "SDDCT" in ('RI', 'RM', 'RN')
      and         CAST (EXTRACT (MONTH FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM-                YYYY ') + substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in : Month
    and          CAST (EXTRACT (YEAR FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM-                YYYY ')+ Substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in: Year
    and          trim ("F0006". "MCRP22") =: Establishment
    and          trim ("F4101". "IMSRP1") =: Division
    Group By    "F42119". "SDLITM"
                    "F42119". "SDAITM"
                    "F42119". "SDDSC1"
                    "F4101". "IMSRP1"
                    "F42119". "SDDOC"
                    "F42119". "SDDCT"
                    "F42119". "SDUOM"
                    "F42119". "SDCRCD"
                    "F0101". "ABAN8"
                    "F0101". "ABALPH"
                    "F4101". "IMSRP2"
                    "F4101". "IMSRP8"
                    "F4101". "IMSRP9"
                    "F4101". "IMSRP0"
                    "F42119". "SDMCU"
                    "F0006". "MCRP22"
    I appreciate the help you can give me

    It seems to me that part of fixing it could be how you join the tables.
    Instead of the humongous where clause, put the applicable conditions on the join.
    You have
    from "PRODDTA". "F0101" "F0101"
    "PRODDTA". "F42119" "F42119"
    "PRODDTA". "F4101" "F4101"
    "PRODDTA". "F0006" "F0006"
    where "F42119". "SDAN8" = "F0101". "ABAN8"
    and "F0006". "MCMCU" = "F42119". "SDMCU"
    and "F4101". "IMITM" = "F42119". "SDITM"
    and "F42119". "SDDCT" in ('RI', 'RM', 'RN')
    and CAST (EXTRACT (MONTH FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM- YYYY ') + substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in : Month
    and CAST (EXTRACT (YEAR FROM TO_DATE (substr ((to_date ('01-01-'| | to_char (round (1900 + (CAST ("F42119". "SDDGL" as int) / 1000))),' DD- MM- YYYY ')+ Substr (to_char (CAST ("F42119". "SDDGL" as int)), 4,3) -1), 1,10))) AS INT) in: Year
    and trim ("F0006". "MCRP22") =: Establishment
    and trim ("F4101". "IMSRP1") =: Division
    INSTEAD try something like
    from JOIN "PRODDTA". "F0101" "F0101" ON "F42119". "SDAN8" = "F0101". "ABAN8"
    JOIN "PRODDTA". "F42119" "F42119" ON "F0006". "MCMCU" = "F42119". "SDMCU"
    JOIN "PRODDTA". "F4101" "F4101" ON join condition
    JOIN "PRODDTA". "F0006" "F0006" ON join condition.
    Not sure exactly how you need things joined, but above is the basic idea. Remove criteria for joining the tables from the WHERE clause and put them
    in the join statements. That might clean things up and make it more efficient.

  • Hi!!I have some problems with the synchronization of my system, and I don´t know how I can solve this!

    My system consists of differents vi´s.Some of them are used to read analogic inputs and digital inputs, using the serial port.
    The values that I read, go through differents vi to be proccesed, and at the end, these values are written in a file, all the values in the same file.
    My problems of synchronization are:
    1. I have one vi per input, and all of them use the same serial port. How can I synchronize them to avoid serial port conflicts? (using queues??) And how can I do, to get differents number of samples/sg with every vi? I have to introduce them in differents loops?
    2. The other problem is that, for example, I want to read 8 samples/ s but I only want
    to write two samples every second. How can I do to avoid stoping the data flow?
    Maybe, my problem is that I want to see the system like
    one block, and I am ignoring that, although all the system works like a block, every part works using a different "speed". I don´t know how tools can I use to combine two ideas, working like an only system( data dependence, some vis need the data of others vi to be able to work) and working getting differents numbers of samples/s.
    I have seen that there are synchronization vis. I am going to glance at them, maybe I find something interesting but I amsure that your help will be very useful?
    Thanks in advanced!!
    Graci

    I think you are pretty much on the right track with Queues. I have implemented a very similar system myself using queues. I have even different systems connected to the serial interface, but I can synchronise them all easily using the following method:
    1) Make a VI for opening the serial port and reading the data. The data (parsed to extract the numbers required) are then stored in an array (Shift register). If the pre-determined time delay is reached (say 5 seconds) the values are averaged and written to a Queue with a defined data type. Save the VI as a VI template.
    2) Make a VI which starts an instance of this template VI for every channel you require. You can use VI Server to set values on the new front panel before you set it's property to "running". Setting a timer value for all can help ensure that the X-Axis of your timing values (if you require) are synchronised. The clue here is to define and initiate a QUEUE per channel. (RS-232_1, RS-232_2 and so on). The QUEUE name needs to be passed to the VI Template before running so that each VI running in the background has an individual link to the main program.
    The second part of this VI simply uses an array of QUEUES, polling them one after another with a timeout of, say 5 ms. If data is found, append accordingly to an XY-Graph.
    I also add in some "Auto termination" in the VI template (MAx number of values allowed in the QUEUE for example) to allow for the background processes to find out if the front-VI is still running or not. There are many different ways to do this, shoose the best for your application.
    With this approach, it's not even important what instrument is connected as long as data is written in a specified format into a known QUEUE. I have also developed systems where I can transparently (almost) drop in VI Templates for instruments with similar functionality (output data) from different suppliers.
    I would post an example, but the time it would take me to clean it up is too large. Sorry. If you have any further questions, don't hesitate to ask further questions.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • I have a iPod touch and i installed it on my other laptop until i had just got another one it says unable to connect to iTunes and i forgot my password and i delete the email and i don't know how i can get my i pod touch to work with my new one email

    I have a iPod touch and i installed it on my other laptop until i had just got another one it says unable to connect to iTunes and i forgot my password and i delete the email and i don't know how i can get my i pod touch to work with my new one email.
    I JUST NEED HELP

    I would contact Apple under your warranty.  I doubt you received a new iPod since Apple's policy is to give you a refurbished iPod. 

  • I want to find my ipad but don't know how. Can I use the Cloud to do this?

    I want to find my ipad but don't know how.  Can I use the Cloud to do this?

    Report to police along with serial number. Change all your passwords.
    These links may be helpful.
    How to Track and Report Stolen iPad
    http://www.ipadastic.com/tutorials/how-to-track-and-report-stolen-ipad
    Reporting a lost or stolen Apple product
    http://support.apple.com/kb/ht2526
    Report Stolen iPad Tips and iPad Theft Prevention
    http://www.stolen-property.com/report-stolen-ipad.php
    How to recover a lost or stolen iPad
    http://ipadhelp.com/ipad-help/how-to-recover-a-lost-or-stolen-ipad/
    How to Find a Stolen iPad
    http://www.ehow.com/how_7586429_stolen-ipad.html
    Apple Product Lost or Stolen
    http://sites.google.com/site/appleclubfhs/support/advice-and-articles/lost-or-st olen
    Oops! iForgot My New iPad On the Plane; Now What?
    http://online.wsj.com/article/SB10001424052702303459004577362194012634000.html
    If you don't know your lost/stolen iPad's serial number, use the instructions below. The S/N is also on the iPad's box.
    How to Find Your iPad Serial Number
    http://www.ipadastic.com/tutorials/how-to-find-your-ipad-serial-number
     Cheers, Tom

  • I'm trying to update my IPAD 2 to iOs 7.1.2 but don't have enough memory to do so.  In I-Tunes I'm told to change my media sync options to gain more memory, but I don't know how.  Can you help?

    I'm trying to update my IPAD 2 to iOS 7.1.2 but don't have enough memory to do so.  In I-Tunes I'm told to change my media sync options to gain more memory, but I don't know how.  Can you help?

    Turn off the check mark to sync your music and also the check mark for the video. Sync the device. This will remove the items from you iPad but still keep them on your computer. Install IOS 7.1.2. Then turn on the check marks for your music and videos and resync the device.

  • How can I change the appe ID that is registred in my Ipad? It was bought for a friend and he put his own ID. I have my ID but I don' t know how I can install it in my Ipad

    How can I change the appe ID that is registred in my Ipad? It was bought for a friend and he put his own ID. I have my ID but I don' t know how I can install it in my Ipad

    Tap on the id in Settings > Store and log out of it and then log in with your id. But if there is any content on the iPad from his account then you are probably better off resetting back to factory defaults via Settings > General > Reset > Erase All Content And Settings and starting 'as new' with it - content is tied to the id that bought/downloaded it so your account won't be able to download updates to any of his apps, and unless his account is authorised on your computer's iTunes and his content is on there then it will be deleted when you sync to it.

  • I have just lost all my contacts from my Mac and my I Phone. Don't know how.  Can I get them back?  Not using Time Machine

    I have just lost all my contacts from my Mac and my I Phone. Don't know how.  Can I get them back?  Not using Time Machine

    If you have no backups, and data has been lost, then it's lost forever. The rest of your data will inevitably follow if you don't back up.

  • I have just got the new iPod touch. Everything is working except my iMessage and I don't know how I can set it up.

    I have just got the new iPod touch. Everything is working except my iMessage and I don't know how I can set it up.

    Illaass
    Gave my grandsons iPods for Xmas. Looks like one of them downloaded an app (text+) and must/may have deleated on hisiPod the iMessage app that was included on both with both iPods.
    I want to ditch this new app (text+) and return iMessage to his phone as they both are wifi only and iMessaget is what they should both use. Ialso have a iPad (wifi only) and a iphone (both on iOS5) and a MacBook on 10.7.2
    Any help as to how to do this (I would prefer not to due a full restore to the affected iPod if possible)

  • I'm having problems upgrading from 10.6.8 to Yosemite.  My computer locks up after the download and installation process.  Does anyone know how I can overcome this problem?

    I'm having problems upgrading from 10.6.8 to Yosemite. My computer locks up after the download and installation process. Does anyone know how I can overcome this problem?

    Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.

  • I have had my mac book pro for about a year and a half and suddenly my dvd player will not play DVDs and i can not play alot of things on full screen. Does anybody know how i can fix this?

    I have had my mac book pro for about a year and a half and suddenly my dvd player will not play DVDs and i can not play alot of things on full screen. Does anybody know how i can fix this?

    This could be several things, but let's get the obvious ones out of the way, first:
    1. Judging from your text, there's no problem with anything stuck in the mechanism; it's more an issue of no being to put in a disk. In other words, you're sure that there isn't a disk stuck in your MBP. (That happens a lot for all computers.)
    2. Go to Applications/Utilities/Disk Utility, and repair the disk. This should take under 10 minutes.
    3. Perform the procedure outlined here:
    http://forums.macrumors.com/showthread.php?
    4. After you're done, leave a message here as to the status of the repair.

  • I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it

    I downloaded an upgrade to my adobe reader today, and ever since my search engine has switched to yahoo and wont change back to google. I have a macbook pro, help please? Does anyone know how I can change this back? I have tried through my settings but it doesnt work

    Hi Timia,
    If you are using Safari as a web browser :-
    Open Safari, go to Safari menu > Preferences > General, and put Google as the homepage. Then, choose Google as your default search engine.
    If you are using Google Chrome as the web browser :-
      Open Google Chrome.
      In the top right corner of the page, click the Chrome menu Chrome menu > Settings.
      In the "Search" section, select Google from the drop-down menu.
    Let me know if you still experience any issue.
    Regards,
    Aadesh

  • I have 3 apple devices and I use the same apple ID for all 3.  I would like to create a new I'd for one of my devices, but do not want to loose the apps on that device.  Anyone know how I can do this?

    I have 3 apple devices and I use the same apple ID for all 3.  I would like to create a new I'd for one of my devices, but do not want to loose the apps on that device.  Anyone know how I can do this?

    Create a new ID:
    On the iPod go to
    - Settings>Messages>Send and receive and sign out your ID and sign into the other one. Make sure that only her ID email address is listed.
    - Settings>FaceTime sign out of your ID and sign into the other one. Make sure that under You can be reached at only the newID email address is listed
    - Settings>iCloud and sign out and sign in with the new one
    - Settings>iTunes and App Store and sign out your ID and sign in with the new one.
    - Apps are locked to the account that purchased them.
    - To update apps you have to sign into the account that purchased the apps. If you have apps that need updating purchased from more than one account you have to update them one at a time until the remaining apps were purchased from one account.

  • I get an error message when trying to sign into the support community with another Apple id. On the pick a username screen I get "an account utilizing this address already exists...." despite trying a few usernames. Anyone know how I can resolve this?

    I get an error message when trying to sign into the support community with another Apple id. On the <pick a username> screen I get "an account utilizing this address already exists.Only one account per email address is allowed on the Apple Support Communities" despite trying a few usernames. Anyone know how I can resolve this?

    This problem has been driving me demented. The instructions that Ivan gives have partially worked for me. By following his link
    "How to find out if you have multiple Apple IDs" I was able to identify that yes I did have two apple accounts using the same e mail address. One was very old that I used to use for the forum boards and one is my much more recent ID that I use for everything these days. So I changed the e mail address for the old account which is associated with these discussion boards and that's the account that I am now posting this from. However even though the two accounts now have different e mail addresses when I try to log onto the boards with my more recent main apple ID I still get all the same errors as described at the start of this thread by rodgers_j. And of course that's the one I want to use so that I only have one itunes account for everything.
    So if anyone has any more hints I'd be very grateful.

Maybe you are looking for