How to make a sum of a subquery which first determine the time period and then the total sum.

Hello

I know how to solve it in two of the query, but I want to merge this in a single query.

I have records in a table with the status 1. I also have records in the table with the State 2 and 3. But the 2 and 3 folders can have a period different kind of these must be determined in advance when this is, mind a deviding through 3 or 12 months.

Double nesting is not allowed with Oracle, I detected. There may be more than 1 card whose status is 2 or 3 and I want to collect these and return as a sum value.

select clk.clickid
      ,clk.uidclickstatus
      ,clk.period
      ,clk.STARTTIME
      ,clk.stoptime
      ,clk.CREATETIME
      ,clk.VOLUME "Open click volume"
      ,sum(tot_volume) --This doesn't work and is my problem!
      ,(select case
                 when ec.period = 'M' then
                    ec.volume
                 when ec.period = 'Q' then
                    ec.volume / 3
                 when ec.period = 'Y' then
                    ec.volume / 12
                 else
                    0
               end as tot_volume
        from click ec
        where ec.uidcontract    = clk.uidcontract --807430
          and ec.starttime      = clk.starttime --Maybe the good reader will be saying why are you deviding, this is now directly related to keep it simple for now
          and ec.stoptime       = clk.stoptime --Maybe the good reader will be saying why are you deviding, this is now directly related to keep it simple for now
          and ec.uidclickstatus in (2, 3)
       ) sourced_volume
from click clk
    ,lscmcontract ctr
where clk.UIDCONTRACT       = ctr.UIDCONTRACT
  and ctr.UIDCONTRACT       = 807430
  and clk.uidclickstatus    = 1
order by clk.uidclickstatus asc, clk.period, clk.starttime
;

Can someone help me how to solve this problem?

I'm not a guru on SQL. Straight motion is not a problem but what advanced...

Thank you

Nico

OK, I've already said I'm not a guru, but I solved my problem. I didn't know that it is possible to put a sum around a case. In the end, it is the solution:

select field
,field
,(select sum(case
                  when clk.period = 'M' and ec.period = 'M' Then
                        (ec.volume)
                  when clk.period = 'M' and ec.period = 'Q' Then
                        (ec.volume / 3)
                  when clk.period = 'M' and ec.period = 'Y' Then
                        (ec.volume / 12)
                  when ((clk.period = 'Q' and ec.period = 'M') or (clk.period = 'Q' and ec.period = 'Q')) Then
                        (ec.volume)
                  when clk.period = 'Q' and ec.period = 'Y' Then
                        (ec.volume / 4)
                  when clk.period = 'Y' Then
                        ec.volume
                  end) as Month_Vol
from ec.table
where ...
  and ...
) volume
from clk.talble
where ...

Nico

Tags: Database

Similar Questions

  • How to make one of my computers line so that I can install LR and PS on a third unit and how do I tell Adobe about which computer is offline while I have only 2 operational at a time?

    How to make one of my computers line so that I can install LR and PS on a third unit, and how should I inform Adobe on what unit is online, at any time, so that I can use the other two?

    Richard,

    You can have the creative cloud installed and signed in on two computers as long as you don't use it on one at a time. Download and install as you did on the first computer, sign in to your Adobe account on the Adobe using your Adobe ID website, download the desktop app from clouds, then download the software.

    You can download the installer for Creative Cloud from here:
    Creative cloud help | Creative cloud desktop.

    After you install the creative Cloud desktop application, you will need to sign in with a login password and Adobe. Then you can install applications. This link provides more information and step by step instructions, if you need: CC help | Download, install, update or uninstall applications

    If you get a new computer, simply log out of creative cloud over one of the other and log on to the new.  Connect, disconnect you and | Adobe Creative Cloud desktop app

    Guinot

  • How to transfer photos from my iPhone to my iPad, put them in albums and then remove them from my iPhone

    How to transfer photos from my iPhone to my iPad, put them in albums and then remove them from my iPhone

    There are several methods.

    You could make a start by looking at this article.

  • How can I know if an external drive has been used for Time Machine and what computer it came with too?

    How can I know if an external drive has been used for Time Machine and what computer it came with too?

    I have several laptops and iMacs. I spent the relocation of the year and only used the MacBook Pro.

    Now I'm trying to figure out which drive goes with which computer

    I connected just a disk seagate 1.5 t and the first thing he did was to ask if I wanted to use it as a Time Machine drive.

    (1) if it is the TM disk accompanying this computer don't would not it have just started upward automatically?

    (2) what happens if I would have said yes?

    (3) I don't even know if it's been activated for TM. Is there a way to tell? It may hold just for iMovie files and other programs associated with a computer from my past.

    All readers of backup Time Machine contains a folder named: Backups.backupdb. If you open this folder, you'll find another folder with the name of the computer that has been saved. If several computers have been saved on the same disk, you will have several folders.

  • How can I find out which updates installs successfully on stop and then install?

    My (6) updates are not installed when I shut down my computer. This has happened for several weeks. I do not force stop or unplug it. I can't understand who (s) update by installing does not correctly. How can I find out which updates won't install correctly and then install them?

    View update history.

    For Windows Vista:
    http://Windows.Microsoft.com/en-us/Windows-Vista/see-which-Windows-updates-are-installed

    For Windows 7:
    http://Windows.Microsoft.com/en-us/Windows7/see-which-Windows-updates-are-installed

    For Windows Vista:

    http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-problems-with-installing-updates

    For Windows 7:

    http://Windows.Microsoft.com/en-us/Windows7/troubleshoot-problems-with-installing-updates

    TaurArian [MVP] 2005-2011 - Update Services

  • How to make a sum of text_field or column with where condition?

    Hi all

    In Oracle forms 6i, I created a form in which there are 5 text_Items (with 20 none of the displayed fields) namely ACCOUNT FD DO, AMOUNT, INTEREST RATE, STATUS and INTEREST_YEAR.

    FD ACCOUNT NO.

    AMOUNT

    INTEREST RATE

    STATUS

    INTEREST_YEAR

    47665

    50000

    1. 11.5

    E

    5750

    37463

    60000

    12

    D

    7200

    47651

    100000

    1. 12.5

    D

    12500

    34766

    70000

    11

    E

    7700

    I want to make the sum of the INTEREST_YEAR where status = 'E '.

    I created a TOTAL_INTEREST_YEAR name field in which I want to display the sum.

    How the sum with where condition?

    Thank you.

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    Oracle form Builder 6i.

    Michael,

    When you write the formula for a calculated item, it does not use PL/SQL expressions (to include built-in DECODING) in Forms 6i.  If there was no conditional control over your calculation, you can simply make your article a summary point and perform the summation over column interest_rate .  However, because your calculation depends on the value in the STATUS column, you will need to use a combination of a calculated item and a summary article because you can't use an IF, DECODE or any other PL/SQL statement in the formula for the calculated item.  Therefore, you need to create a function in the knot of program units and call the function in your formula.  I tested it using the following code and it worked correctly.

    First, create the following function in the node of the object browser program units.

    FUNCTION calc_interest RETURN NUMBER IS
         n_ret_val  NUMBER := 0;
     BEGIN
       IF ( :YOUR_BLOCK.STATUS = 'E' ) THEN
           n_ret_val := :YOUR_BLOCK.interest_rate;
       END IF;
       RETURN n_ret_val;
    END calc_interest;
    

    First, you must change the property to BLOCK request all archives = Yes

    Then, open the palette of your calculated item property, and set the following properties:

    1. calculation = Formula

    2 property Forumla = CALC_INTEREST

    3. point data base = No.

    Now create a second item in the table not based on in your block that will display the amount of the interests summarized.  Open the palette property for this element and set the following properties:

    1 Data Type = number

    2 calculation Mode = Summary

    3. function = sum

    4 summarizes point = "name of your element calculated.

    5 base of data point = No.

    6 canvas = "your canvas.

    When you query your block, you should see the sum of all records where STATUS = 'E '.

    It worked for me, in my example form that I created so this should work for you.

    Craig...

  • How to make buttons that animate on mouse to return to the original state * gently * mouse off?

    The title pretty much sums up what I'm doing: I have not started digging using the script in Flash but, being very well a beginner.

    I created a simple file using video clips nested in the buttons then that when I mouseover a letter, she bobs up and down, but I can't work on how to make it back to its origin 'up' State * gently * when the mouse is moved away.

    Any suggestions?  If it must involve the script know that I am a total noob!

    Here is a tutorial of mine that illustrates the benefits and disadvantages of the different techniques of creation of button:

    http://www.snorkl.TV/2010/08/Flash-MovieClip-buttons-vs-simple-buttons-five-ways-to-build-UN button.

    you need to may very well add to these files and maybe learn a little more, but it should make for a good starting point

    -carl

  • The HP ENVY TS m7 laptop: how to make an HP Support Assistant icon to appear in the Notification area of the taskbar Windows 10?

    I am running Windows 10 (x 64) (build 10586) on my laptop HP ENVY TS of m7 with HP Support Assistant 8.1.40.3. I'm used to seeing the blue Support Assistant of circular background of question mark icon located on the right side of my taskbar Windows in the notification area, just to the right of the up-carat for 'display the icons '.

    However, about 2 days ago the Assistant to support automatically downloaded and installed the latest version of himself. The '? ' icon disappears from the notification area of the task bar and appeared to place on my desk. I clicked on the desktop, and then click icon on "PIN to Desktop". It pinned icon Assistant decision-making support on the left side of my taskbar with icons for Windows Store File Explorer and other icons open programs.

    I tried just dragging the icon Wizard help to the right of the Notification area of the taskbar, but that cannot be done. Please give me detailed instructions on how to get back the icon wizard helps to where I'm used to seeing.

    Thank you for your help.

    DavidPK wrote:

    Hello

    Another option, you may need to check is the following.

    Launch of HP Support Assistant.

    Click the gable of parameters to the upper right.

    In the following Panel, make sure the "show an icon in the taskbar" entry (see the option highlighted in the image below) is checked - if not, click in the box enter a tick, then click on the "Save" button.

    Kind regards

    DP - K

    Hello once again, David,

    Success at last! I uninstalled HP Support Assistant and reinstalled. After the installation, I found that the wizard help icon was now right of my bar Windows 10 tasks in the notification area, where I'm used to seeing. See the image below. If this topic is now closed.

    Thanks for all your suggestions and help, which helped my analysis of this problem and its possible solution.

    All the best wishes and cheers,

    Joel

  • How to make still photos of my camera of Lenovo to the appropriate library to upload on a social networking site (Facebook, not)?

    First of all, I'm 50 years old and I grew up in the time before the PC, so I am very naïve.

    I have a laptop from Lenovo and it has a camera in it. I recently discovered that it can take still pictures, so I took some pictures of me.

    Now I want to download pictures to an online community, I belong to where I have a profile. But the photos are not in my images on Microsoft Word, or in Windows Media Player or any library I can find.  They are in the box in the photo section.  How can I get them on the part of the camera on the computer in a place where I can then download them to my profile online? Where should I store, and how to make them here?
    I appreciate your help.

    Hi James,

    I see you want to download photos of the Lenovo built in webcam for a social networking site still. I'll help you with this problem.

    1. what operating system is installed on the computer?

    2. what security software is installed on the computer?

    Please follow these steps and let us know the status.

    1 - click on "Start" and start the webcam software. Every computer manufacturer take its computers ready webcam with a specific software for the control of the camera.

    2 - Click on 'Snapshot' or 'Take picture' (or similar) in the program to capture still images. Most of the programs of webcam show you what see your webcam, as soon as the program is open. When you move, the webcam image also moves. Specific commands vary from one program to a program and manufacturer in the manufacturers, but the standard webcam software has a "snapshot" command to take a picture.

    3 - Click on 'Tools' and 'Settings' (once again, or similar) to change the way the webcam records still images. You can configure the quality of the photos up to a preset maximum resolution. A webcam software allows you to save a series of images or to add digital effects to the pictures. That depends on the camera photo and its software by default, too. While in the 'Settings' window, find out where the pictures are stored. Each program stores pictures in a different location.

    4 - Click 'Start' and 'Computer' to open a file browser. Find the folder where the webcam stores its photos of step 3 to change the photos with a graphics program or to delete and rename files. To send photos to your friends and family, open your email and attach photos to this folder. Webcams store photos in smaller resolutions, so you never get hurt to send these files as attachments, even with a very slow Internet connection.

    Let us know if you need assistance with any windows problem. We will be happy to help you.

  • How to make my email more small it is too big for my screen and it too far on the right, it is when I click on create mail and it's huge

    How can I make my smaller email is too big and it was too long on the right side, it is when I click on create email and when it opens I do not have the right of it

    You can move the window by grabbing the title bar at the top. Once you have a visible advantage, place the cursor on the right on that edge, left click and drag it to the desired size. First close all other windows and the latter so that Windows remember their size.
     
  • Can someone tell me how to make a backup of 13 elements just in case my phone broke and I need to reinstall?  I use Windows 7.  Thank you!

    Can someone tell me how to make a backup of the elements 13 just in the case of my laptop broke and I need to reinstall using Windows 7.

    There should be no need to.  Download files are available through a few places and they should stay that way.

    PES 10, 11, 12, 13 - https://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-downloads.html

    PE 10, 11, 12, 13 - https://helpx.adobe.com/premiere-elements/kb/premiere-elements-downloads.html

    You can also download the demo version of the software through the page linked below and then use your current serial number to activate it.

    Don't forget to follow the steps described in the Note: very important Instructions in the section on the pages of this site download and have cookies turned on in your browser, otherwise the download will not work correctly.

    Photoshop/Premiere Elements 13: http://prodesigntools.com/photoshop-elements-13-direct-download-links-premiere.html

  • How to make page 2 AutoNumber as page 1, without changing the sides?

    I understand the automatic numbering pages, but sometimes it's a little tricky.  I have a finished booklet where the inside of the cover should be page 1.  When I go to the page numbering and him say to make Page 1 Page 2, he wants to move the left page of the spread to the right that I don't want.  How do I keep it on the left side?

    You will need to disable the shuffle in the pages Panel context menu.

  • How to make a purchase on a family account without loading the main map

    My daughter has a few games it plays I want to buy addons (in-app purchases or upgrades) for. We put in place on a family account and my wife is the "family card" (my card is listed as an "extra payment method"). I want to load these purchases to my own card, is this possible?

    Ideally I'm not

    (a) must go into a shop and buy a gift card for iTunes store whenever I want to do it - not very convenient

    (b) remove the family payment method and change it to my own - my wife purchases movies and prefers to pay itself

    (c) withdraw from the family account - I guess if I do that I'll lose all family applications, movies etc.

    I tried two things suggested by the Apple support: send me a gift of iTunes via the Apple website, that doesn't work (it would not allow me to buy) and make the purchase via iTunes and send me a gift card (it worked, but it has charged to the family card).

    I feel like there must be a simple way to buy something with my Apple ID without a card of my wife, but I can't understand it!

    With the members of the families sharing family purchases will use their own balance if they have one, otherwise card organizer will be charged - family members cannot use their own card, and the organizer can not use a scale.

    Map of your wife so all purchases that your daughter (assuming she's using his own account) will use its balance, and if it has one (or if it does not cover the total price of the item) will be charged (the surplus if the balance of your daughter isn't enough).

    With your wife of gift card is billed as she is the Organizer.

  • How to make a vector file of Adobe CC draw on the IPAD in Adobe Illustrator CC on the PC?

    As the title says.

    I designed a sticker on Adobe draw CC and I need to upload it to a website like CMYK, 300 DPI and a specific size in inches.

    To save the file, I need to transfer it to the PC first because the CC draw Adobe does not allows you to select the features to save a file.

    I can 'send to adobe illustrator' or 'send to adobe photoshop' option on the ipad, but it seems that it is not a vector when file sent.

    Any ideas?

    If you send the illustrator of the draw, it will automatically convert to vector illustrations.

    1. make sure that you are connected to the PC and the CreativeCloud iPad with the same subscription that you use to launch Adobe Illustrator.

    2. with Internet on iPad, simply click: send to Illustrator.

    You even don't need to have Adobe Illustrator running, it should appear on your PC automatically.  If it is already running, the image will transfer as vector illustrations.

    If you have layers in the draw, they will appear as layers in Adobe Illustrator as well.

    You can then continue your design in Illustrator.

    (If you use Photoshop, it will stay in a layer, raster format)

  • How to make an object or a menu to stick on the left edge of the screen?

    I want the menu on the left to look like here http://muserocket.com/TF/bonesa/ How to do paste left on any monitor?

    Use the pinning control in the Control Strip to pin to your sidebar to the top left of the browser window.

Maybe you are looking for

  • My yahoo mail download more.

    My yahoo mail always downloaded fine until yesterday. Now, it will only download one email at a time. I get a few hundred per day. I checked my settings and they seem to be good. Can you help me?

  • Browsers

    I run three browsers on my MBP and continually find Firefox in particular and sometimes Safari, duplicating itself and which appear on the desktop, and as a copy in the dock.    Anyone know why this is happening?

  • Error: "file is not in drive F" while trying to uninstall programs

    Original title: uninstall problems I'm trying to uninstall XP different programs, but error message keeps coming up that the file is not in drive F, but drive C is where they are.  How can I change the location of the reader?

  • How can I update on Linux

    I installed a VM device (OTN_Developer_Day_VM.ova) that I downloaded recently from 4.1.0.19. When I try to help, check for updates, he sees version 4.1.3. Can I just use the number of rounds of SQL Developer 4.1.3 to update SQL Developer?

  • Moisture calculation logic

    HelloI have a question of my client.What's happen if I manage moisture info by the decomposition of matter (1 water content of the eachcomponent) for an ingredient and at the hardware level to another and I have put together in a formulation?I know t