How can I write this in sql? (an another headcracker challenging the report)
Hi guys!I need to create / generate a report. I intend to do all of this with only pure SQL.
Been cracking my head for days, but nothing helped.
Hope you gurus here me straightened out.
Here it goes. I have a table
TABLE USAGE_REPORT
------------------------------------
Date date of daily
BalanceCF NUMBER - the sum of initial departure or (balancebf)
Topup_amount NUMBER amount topup so far
Usage1 NUMBER - duration of the use of $ on certain prod
2 NUMBER - duration of the use of $ on certain prod
BalanceBF NUMBER - BalanceCF + refill - usage1-2 (which is also the next date of BalanceCF)
-----------------------------------------------
Example1
Please see this link
http://img9.imageshack.us/img9/708/88149028.gif
asumming that is my sql
WITH dates in the FORM
(
SELECT trunc (sysdate) + level dmy
DUAL CONNECT BY level < 366
),
Charging as
(
As the SELECT trunc (purchase_date), sum (payment_amount)
Purchase
Trunc GROUP (purchase_date)
),
Usage1 as
(
As the SELECT trunc (connect_date), sum (charged_amount)
OF tab1
WHERE prod_id = "xxx".
GROUP BY trunc (connect_date)
),
2 as
(
As the SELECT trunc (connect_date), sum (charged_amount)
Of THE tab2
WHERE prod_id = "yyy".
GROUP BY trunc (connect_date)
)
SELECT * DATE D
LEFT OUTER JOIN RELOAD T
WE (D.DMY = T.DATED)
LEFT OUTER JOIN USAGE1 U1
WE (D.DMY = U1. DATE OF THE)
LEFT OUTER JOIN U2 2
WE (D.DMY = U2. (DATED);
However
T1) how can I start to 'launch' the 1st row
BALANCECF so that i can do the math
of
BALANCECF + REFILL - USAGE1 - 2 = BALANCEBF
Q2) how can I put the value of BALANCEBF in the 2nd line of BALANCECF to make more calculation?
Q3) is that it has something to do and connect? parent-child relationship
Q4) brief how to make it look like the photo attach above?
Help, please!
Best regards
Noob
I use 200 as initial balance_cf. did you not sample data, so code below is not tested:
WITH dates as (
SELECT TRUNC(SYSDATE) + level dmy,
200 balance_cf
FROM DUAL
CONNECT BY level < 366
),
topUP as (
SELECT trunc(purchase_date) dated,
sum(payment_amount) topup_amount
FROM purchase
GROUP by trunc(purchase_date)
),
Usage1 as (
SELECT trunc(connect_date) dated,
sum(charged_amount) usage_amount
FROM tab1
WHERE prod_id = 'xxx'
GROUP BY trunc(connect_date)
),
Usage2 as (
SELECT trunc(connect_date) dated,
sum(charged_amount) usage2_amount
FROM tab2
WHERE prod_id = 'yyy'
GROUP BY trunc(connect_date)
)
SELECT dmy,
balance_cf + sum(topup_amount - usage1_amount - usage2_amount) over order by dmy rows between unbounded preceding and 1 preceding) balance_cf
topup_amount,
usage1_amount,
usage2_amount,
balance_cf + sum(topup_amount - usage1_amount - usage2_amount) over order by dmy) balance_bf
FROM DATES D LEFT OUTER JOIN TOPUP T ON (D.DMY = T.DATED)
LEFT OUTER JOIN USAGE1 U1 ON (D.DMY = U1.DATED)
LEFT OUTER JOIN USAGE2 U2 ON (D.DMY = U2.DATED)
ORDER BY dmy
/
SY.
Tags: Database
Similar Questions
-
How can I write this loop?
How can I write this code works as follows.
When btn1 is clicked, SenderLoad must be 'clay' AND click btn2, SenderLoad must be 'iron', etc...
var mgB:Array = [btn1, btn2, btn3 btn4];
var mgBW:Array = ["clay", "railway", "cotton", "leather"];
var SenderLoad: LoadVars = new LoadVars();
var ReceLoad: LoadVars = new LoadVars();
var mgNum:Number = 0;
for (i = 0; i < mgBW.length; i ++) {}
mgBW [i] .onRelease = function () {}
mgNum ++
SenderLoad.word = mgB [mgNum];
SenderLoad.sendAndLoad ("http://www.web.com/my.php", ReceLoad, "POST" ');
ReceLoad.onData = {function (src)}
var messageA:Array = src.split(",,,");
ldrB2.html = true;
for (var i: Number = 0; i < messageA.length; i ++) {}
var a:Array is get [i].split(",,");.
ldrB1.htmlText += a [0];
ldrB2.htmlText += a [1];
}
}
}
};
If you use the movieclip buttons:
var mgB:Array = [btn1, btn2, btn3 btn4];
var mgBW:Array = ["clay", "railway", "cotton", "leather"];
var SenderLoad: LoadVars = new LoadVars();
var ReceLoad: LoadVars = new LoadVars();for (i = 0; i
.Ivar Construction [i] = i;
mgB [i] .onRelease = function() {}
SenderLoad.word = mgBW [this.ivar];
SenderLoad.sendAndLoad ("http://www.web.com/my.php", ReceLoad, "POST");};
}
ReceLoad.onData = {function (src)}
var messageA:Array = src.split(",,,");
ldrB2.html = true;
for (var i: Number = 0; i
var a: Array = get [i] .split (",");
ldrB1.htmlText += a [0];
ldrB2.htmlText += a [1];
}
}; -
I want to disable Photoshop CC on a PC and install on a Mac. How can I do this? There is no "disable" in the Help menu PS CC
my information is that automatically install a third instance of CC will you sign one of two previous currently active facilities.
My understanding is that connecting to activate a 3rd instance of CC disables all activations
Maximum activations exceeded subscription or product launch Cloud creatives
It is a way to the brute force of your entire activation status reset if one or more previous activations is no longer available to turn it off.
-
How can I load updates from pilot to another pc using the ethernet cable?
How can I load updates from pilot to another pc using the ethernet cable?
You would be better to use a flashdrive rather than an Ethernet cable. To connect using an Ethernet cable you need a crossover cable and then configure the network cards.
I hope this helps.
-
How can I write this small function to create the number of strips, please?
Guys,
How can I have a create table according to the argument passed. I'm doing this right?
function createArray(n:int):Array
{
for (var i: int = 0; i < n; i ++)
{
nArr var = new Array();
}
return nArr [i];
}
Thank you very much.
var aArraySet:Array = createArraySets (5); create 5 paintings
Table 1-> aArraySet [0]
Table 2-> aArraySet [1]
Table 3-> aArraySet [2]
Table 4-> aArraySet [3]
Table 5-> aArraySet [4]
function createArraySets(n:uint):Array
{
var aArraySet:Array = new Array();
for (var i: uint = 0; i
{
aArraySet.push (new Array();
}
Return aArraySet;
}
-
How can I write this GREP query correctly (CS4)
Hello.
I have a, uh, interesting problem. I got a HUGE page layout document. copy typed in word... and have ' cleaned every regular:
-to - and multi-retourne to the simple and so on.
However, the editor has throughout the copy (by effect? LOL) decided to single space the letters of the words randomly in the text as follows:
It is a E x a m p l e, of what he has done and is a massive p r o b l e m / e h a d a, c e h!
Ok... I try to work on the proper GREP but have so far failed. What I need, is to find any space white between two simple letters and replace it with, well, to remove them. I'm into hysteria with myself as it seems so simple and yet I can not understand it.
So, here I am enlisting the help of the GREP Boffins out there.
Thank you sincerely
Grant
It would be: search
(? <><\w) (?="\w\">)
replacing it with nothing - assuming that these spaces, as Peter points out. It really could be followed as well. It's (I think) so a style German emphasis to the space of words (but not as big as a set of 'regular' space).
You'd also better to check than if there are really just words at random, otherwise you will lose focus. If you want to mark the words with a character style, you cannot use the above GREP. Interestingly, I can not write a single GREP that removes the spaces and add a character style to the text at a time... But you can use the GREP
\<\w( \w)+\="">
with a character style in the replace with formatting field to mark any text with a style, and then remove the outdoor areas.\w(>\w)> -
How can I download one foot details page as well as the report in Excel
Hello
I would like to download the dashboard page footer details as well (the user, report number page and DURATION info information bottom of dashboard) as well as my report when I download in excel. How could do?
Please suggest!
Thank you
SMAHi ADM,.
Reference: http://varanasisaichand.blogspot.com/2010/02/adding-footer-view-to-reports-in.htmlYou will get a footer in the next click report on insert filed you ll get all the options what are you are looking for, and then save the report... > download to Excel
Thank you
Saichand.v -
How can I build this cluster? I don't like the one I created (too big)
Hi everyone, I am working with a Vision VI and the problem is that I need to create a cluster to connect to a terminal called the VI Vision settings (IMAQ County objects). These parameters include the Boolean values of type long and unsigned word. I saw it in a pdf document:
I like how it looks because it's in a small space.
It's the one I created:
(Please ignore the red numbers 1 and 2)
And the schema looks like this:
If anyone knows how to do a VI as the first picture, please report it.
I thank very you much for your answers and comments.
P.S. I use LabView 2009, maybe some features are not available in versions of newers.
Right-click the Terminal want control to, and then select Create a control. This feature is not going in any version of LV
-
How can I fix this error I get everytime I open the program?
This happens everytime I open the muse. It is located in the muse and nothing else. I uninstalled and reinstalled and I have all my files adobe off my computer and then re install and it has not yet resolved the issue.
Adobe Muse CC has encountered an error and will now close. Please report the last actions bit that you have taken to this error to the Adobe Muse CC team. Failure of the assertion in the file "/ work/Build_Blob_Mac/dvaapp/Muse/project/mac users/erato/Desktop/workspace /... /.. '. "/ src/MuseIMSC onnector.cpp ' on line 856: incompatibility of user fUserEmailId id == dvacore:utility:UTF8to16 (emailID)
Hello
Please the following steps and you'll be all set.
1. disconnect Muse by going to help > log out. (if you see the option to do so)
2 disconnect from the creative Application of cloud. (Steps are mentioned in the link disconnect, sign in |) Creative Office Cloud app), then quit the Application in creative cloud.
3 Rename the folder "OOBE" to "OOBEold".
MAC: (This file can be found at Finder > go > go to folder > enter ~/library/application support/Adobe > press return)
Widows: (This file can be found at C:\Users\
\AppData\Local\Adobe )4 restart the Muse, sign in with your Adobe ID
Please let me know if the steps above do not work, or if you have any confusion.
Concerning
Vivek
-
I use standalone converter where I am converting my local windows 7 in vmware fusion 4 at the exit. When I made the migration wizard previously, I had an output of a windows7.vmwarevm file. However, when I made the converter, I had a folder called windows7. In this case, I had several files.
Is there a way for me to convert all these files into one file, that is to say: windows7.vmwarevm? do I need to use the converter or other vmware tools?
Welcome to the community,
Please take a look at Re: how to convert a package/package of my folder on drive hard/vmware fusion? to see if that helps. This is a pretty old post, but I think that it is still valid.
André
-
How can I adapt this script GREP to find and replace the current open document?
// Get the current selection var doc = app.activeDocument; var sel = doc.selection; var frame = sel[0]; if (!frame || frame.constructor.name !== "TextFrame") { var msg = "Please select a text frame containing"; msg += " the story you wish to format"; alert(msg); } else { var story = frame.parentStory; // Reset the Find/Change options app.findGrepPreferences = NothingEnum.nothing; app.changeGrepPreferences = NothingEnum.nothing; // Remove all soft returns, then replaces all double spaces to single spaces app.findGrepPreferences.findWhat = " \s+\n"; app.changeGrepPreferences.changeTo = " "; story.changeGrep(); // Remove all multiple spaces app.findGrepPreferences.findWhat = "\s+"; app.changeGrepPreferences.changeTo = " "; story.changeGrep(); // Split Listings WITH Images app.findGrepPreferences.findWhat = "(\d\d-\d+.*)\t(?!~a)(.*)\t(.*)\r"; app.changeGrepPreferences.changeTo = "$2\r$1\t$3\r"; app.changeGrepPreferences.appliedParagraphStyle = "Description"; story.changeGrep(); // // Split Listings WITHOUT Images // app.findGrepPreferences.findWhat = "(?<=~a)(.*)\t(.*)\t(.*)\t(.*)\r"; // app.changeGrepPreferences.changeTo = "$1 $2\r$3\t$4\r"; // app.changeGrepPreferences.appliedParagraphStyle = "Description"; // story.changeGrep(); // Format Pricelines app.findGrepPreferences.findWhat = "^(\d\d-\d+-\d\t.*)\r"; app.changeGrepPreferences.changeTo = "$1\r"; app.findGrepPreferences.appliedParagraphStyle = "Description"; app.changeGrepPreferences.appliedParagraphStyle = "Priceline"; story.changeGrep(); }
Hello
story.changeGrep (); ==> This sets a goal of change
To replace it any doc as target
doc.changeGrep ();
and remove part of the code that is cause of selection type do not need you to check
Jarek
-
How can I change my current PayPal to another address in the payment Options?
I need to change the address in the payment Options PayPal, because I want to start to pay another PayPal account.
I have an annual plan, paid monthly, can I cancel it and create a new plan without being charged with the duty of remaining contract?
Manage your membership and your payment. Creative cloud
With regard to the cancellation of a plan without penalty goes, this is something only Adobe Support can organize to contact you through. I guess you have to pay for the new system first before they will consider allowing it.
To the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...
Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache. If it fails to connect, try to use another browser.Creative cloud support (all creative cloud customer service problems)
http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN ) -
I have a micro card. I used to put photo files. Today I'm trying to remove them and I get a message that the card is write protected. How can I disable this?
I guess you put the micro card in full-size SD card reader? Look on the side of the SD card. There is a small switch that is write protected. Put it to the other position. -
1. I have a field where I need to write a formula for a division problem: (power/population) / 365. When I use the simplified field notation I get an error: the entered value does not match the format field. I want the answer as a number with no decimal point. If I format the field to 'no format' I don't get an error message but the answer comes with up to 10 digits after the decimal point. I'd rather have the answer in integer without figures after the decimal point. How can I write this in the custom calculation script?
2. on accessibility - I never checked on the display/a Mode and unlocked the Acrobat/PDF compatibility. Some users do not have a problem by filling out the form, but others are not allowed to fill that PDF/A is enabled for their document. Is this something on their end? Or is it something on my end blocking them?
If you multiply by 100, it appears correctly. But if you need to retain the value of the field, you need to use a script to Format custom instead. If you need help, post again.
-
How can I get this popup of Yahoo to stop?
When browsing, a popup of Yahoo appears often invites you to add an extension of yahoo. I don't want the extension, but this option is not given. All I can do is close the popup only to reappear a few clicks later. How can I get this popup to stop? I have the box "block pop-up windows" checked in the preferences.
- 1 Download Firefox for all languages and systemsv.41 {web link}
- 2 Uninstall Firefox on your computer {web link}
DO NOT REMOVE your profiles. - 3 after that, restart the computer. Then, run the full installer.
Maybe you are looking for
-
In case of problem with my Apple Watch.
How to activate my Apple Watch? Won't turn on, won't charge. What can I do? * it turn off by itself starts again. * I try to reactivate it on the right button (Nothing) * I try to load it (Nothing) was hot... * change of cables (Nothing) Apple Watch
-
How to remove FCP7 rendering files, using FCPX or Finder
Hello I am trying to eliminate unnecessary files. For any project FCPX, I see that there is a process to remove the render files. But what I do with projects created in FCP7? These are projects which have had their XML files imported for use in FC
-
Deskjet1510: Deskjet1510 install not on XP SP3
I try to install the XP SP3. I tried all combinations of things I could think or others suggested on this site. The icons are on the desktop... shop supplies etc. When I plug the printer in, windows detects it and says it's installing, then it stops
-
How to recover data after the upgrade to Windows XP Home Edition?
Original title: lost data My Windows XP program has been replaced by Windows XP Home Edition. Some data was not justified. Is it possible to recover the data?
-
My ISP is disconnected. How it reconnected?
My ISP is disconnected. How it reconnected?