How to format the data below


Hi, I have the following data in the rows, but how can I format in below format using SQL or PL/SQL

Examples of data


create table test_temp (invoice_num varchar2 (20), gl_date date, amount, type_of_inv varchar2 (2));

insert into test_temp values ('1000765', 30 June 2013 ", 800," DM");

insert into test_temp values ('1001767', 1 July 2013 ', 1000, "DM");
insert into test_temp values ('1001789', 3 July 2013 ', 1000, "DM");
insert into test_temp values ('1001874', 10 July 2013 ', 500, "DM");
insert into test_temp values ('1001876', 11 July 2013 ', 500, "DM");

insert into test_temp values ('1001768', 1 July 2013 ', - 800, 'CM');
insert into test_temp values ('1001769', 2 July 2013 ', - 1500, 'CM');
insert into test_temp values ('1001783', 2 July 2013 ', - 1000, 'CM');

insert into test_temp values ('1001875', 11 July 2013 ', - 500, 'CM');


Select a.* from (select gl_date, invoice_num, type_of_inv, quantity of test_temp where type_of_inv = 'DM'
Union
Select invoice_num, gl_date, type_of_inv, amount of test_temp where type_of_inv = 'CM') a
order of a.type_of_inv, a.gl_date, a.amount


invoice_num gl_date amount type_of_inv
1001768 1 JULY 13-800 CM
1001769 2 JULY 13 CM-1500
1001783 2 JULY 13-1000 CM
1001875 11 JULY 13-500 CM
1000765 30 JUNE 13 DM 800
1001767 1 JULY 13 DM 1000
1001789 3 JULY 13 DM 1000
1001874 10 JULY 13 500 DM
1001876 11 JULY 13 500 DM

-output must be below the order by gl date

Choose the cm and apply against DM order by gl date


1001768 CM is applied on DM 1000765 amount - 800 + 800 = 0

CM 1001769 is applied on DM 1001767 amount - 1500- + 1000 = 500

CM 1001769 is applied on DM 1001789 amount - 500 + 1000 = 500

CM 1001783 is applied on DM 1001789 amount-1000 + 500 = - 500

CM 1001783 is applied on DM 1001874 amount - 500 + 500 = 0

CM 1001875 is applied on DM 1001876 amount - 500 + 500 = 0

The logic is less than

In the test_temp table, I have my two CM and DM stored,

I have to write a query, or a PL/sql program to get the below output.
The logic to retrieve the output here is as follows

Get the first CM and get the first DM to add the amount of CM with amount of DM up to its sum (amount of cm + size DM) = 0
with less date GL

who will give me the first production line

1001768 CM is applied on DM 1000765 amount - 800 + 800 = 0, now I can take the next CM because its amount is zero


get the next CM with less gl date to apply against the DM

1001769 CM is applied against 1001767 with amounts - 1500- + 1000 = 500

then my amount after worn here is still not zero if the same note of credit (on the left - ve amount of CM)
must be applied on the next DM


1001769 CM is applied against 1001789 with amount (-500 + 1000) = + 500

so in this case (+ amount is from left to right on DM), get the new CM

1001783 CM must be applied on DM even because always the amount was left with amounts DM 1001789 (-1000 + 500 = 500)

now, in this case - ve amount is left cm

so even CM must be applied on the next DM

1001783 is applied on the next 1001874 DM with amounts-500 (to the left of the previous) + 500 (amount of this DM) = 0
(In this case sum is zero, so I can choose new CM)

get next CM 1001875 and applied on the next 1001876 DM with amounts-500 + 500 = 0

Hope this is clear, or let me know please

Thanks a ton of Frankkulash...

Tags: Database

Similar Questions

  • How to format the data to a custom group

    Hi all

    I have a PivotTable with actual expenditures and Budget as some accounts and columns in the rows. Since I'm on the hierarchical column of account, I created custom groups for accounts using the component stages of selection. For example, I created a new group called Profit to combine 3 different accounts of profits and display a result row.

    Now I want to format the data for the group to profit. I right-click on the Profit Group, choose to change the Group and click the Format button on the lower left corner. I add a shape, for example the borders. When I now discover the PivotTable, borders have been applied to the label of the group, so the word Profit is now defined. However, the values in the columns of actual expenditures and Budget have not a border. Don't know what Miss me, but I want both the group label and the values to be formatted in the same way.

    How can I formatting the data values for the custom group?

    Hi user,

    Expected behavior, it won't format the actual values and the Budget. Only the group will be formatted.

    Kind regards
    DpKa

  • How to format the data back of JMX

    I want to fomat dates back to JMX on foglight Server (5.6.5).

    "Ex: convert date format 'long' ' String (PST).

    Also, can I format the data on the dashboard in a different format?

    Ex: Covert "MM/DD/YYY" to "DD-MM-YY".

    I am unable to make use of 'Deriverd' but you need to know if it is possible for data formatting with out creating "Derived Metrics"

    Thank you.

    As usual, in Foglight, there are several ways of doing things, and most things are possible.

    Remember that the date you see is probably not a string format, but a java rendering Date (similar to what you see) or Timestamp objects.

    What you are looking for on a dashboard is a different rendering engine, an object that converts the presentation of the data from one format to another.

    There are many kinds of converters that come with Foglight, including fully customizable Date converters.

    The model on a Date Converter personal property can be used to do almost anything.

  • How to format the date/time field to pathern YYYY-MMM-DD

    Hello

    I'm on LC Designer ES2

    It is for the date format Date specifying, automatocaly view on my form.

    Think, how can I change display of the date to 2015-03-20 field. The default display 15/03/20

    Thanks fot all help

    Stone

    H, I empty the date/time field and recreate.

    Everiting is OK

    Thank you!!!

  • How to format the date in rss view rss/xml pages

    I am the consumption of some RSS FEED and I was wondering how can I change the format for the way the date is displayed... for example to only show this 20/02/2009 or it no longer displays the hour, it was published... Thank you

    whatisgood wrote:

    But is there a way to change this as a preference or a framework of Dreamweaver?

    If there was, I would have used that rather than offer a solution of code.

    XSLT is a complex formatting language markup. XSLT 2.0 has the date format functions, but they are not supported by the parser used in the XSL transformation server behavior.

    To be honest, while the XSL transformation server behavior does a good job, you can consume a RSS feeds with just a few lines of code with PHP 5.2. Try this:

    channel->item, 0, 5);
    foreach ($first5 as $item) {
         echo "

    $item->title

    "; preg_match('/(?:\w{3},\s)?\d{1,2}\s\w{3}\s\d{2,4}/', $item->pubDate, $m); echo isset($m[0]) ? "

    $m[0]

    " : ''; echo "

    $item->description

    "; } ?>

    Retrieves the first five items of the RSS feeds from the BBC, which strips the pubDate of leave. It uses SimpleXML and SPL iterators.

    The code is very advanced, but it is just one example of the type of thing that you can get if you're ready to dive into the code and do not always rely on Dreamweaver does everything for you.

  • How to format the date/time display tips?

    For those of you who know not:

    One of the attributes in VO is of type Date. To display the date in the format ' 10/25/2009 23:45 ', I only managed to display "10/25/2009-11:45" with only the slightest idea of the few examples provided to view tips when you do the formatting (format mask that I use is DD/MM/YYYY HH: mm). "." I'd appreciate it if someone could give advice how to display the part of the mask format AM/PM. Or better yet, to direct me towards a source of reference for this formattnig.

    Thank you!


    Newman

    Newman,

    As suggested by Puthanampatti, you must use 'a' in the date pattern display AM/PM.
    You can find date and time patterns in [doc API SimpleDateFormat | http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html] who described on letters to use for each model that you can also use with hints of display attribute in VO.

    Jean Lou

  • How to format the date?

    Hi all

    I use JDev 10 g.

    And I have a string like 'My Sep 19 00:00:00 IST 2009'. I want this date to be converted
    format of Date Oracle Houston as: "MM/dd/yyyy".

    Please help me how can I achieve this. I tried with the method oracle.jbo.domain.Date.formatText)
    but no use, it throws an exception.

    Thank you
    Isabelle Sanjaykar

    Sanjaykar,

    Have you read [url http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html] the javadocs for impossible? You must pass a string to its constructor, which is the format used by your channel.

    As an indicator, your string starts with'D EEE MMM' - read the javadocs and you can provide the rest of the chain.

    John

  • How to recover the date in a specific format on button clicked?

    I'm trying to update the date in a data template on a user clicks the button, but unfortunately the Date() function gives just a format long unncesseray.  I want just the day/month/year (i.e. 10/09/2013).  How to change the Date() function to achieve this?

     Button {
                                        leftPadding: 30
                                        rightPadding: 30
                                        preferredWidth: 150
                                        horizontalAlignment: HorizontalAlignment.Center
                                        imageSource: "asset:///images/ic_add.png"
                                        onClicked: {
    
                                            rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, Date(), parseInt(ListItemData.lat) + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                        }
                                    }
    

    Thanks in advance.  Solutions and love will see for those who help.

    Kind regards

    Brandon

    I was actually able to find a workaround simpler.  I just used objects attached within the key and attached to a date function:

    Button {
    
                                        imageSource: "asset:///images/ic_add.png"
                                        onClicked: {
    
                                            rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, datefield3.text, parseInt(ListItemData.lat) + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
    
                                        }
                                        attachedObjects: [
                                            Label {
                                                id: datefield3
                                                text: {
                                                    var today = new Date();
                                                    (today.getMonth() + 1) + "/" + today.getDate() + "/" + (today.getFullYear() - 2000);
                                                }
    
                                            }
                                        ]
                                    }
    
  • How to use the date with the report parameter format

    Hi all

    How to use the date format with this tag function,

    <? param@begin:P_FROM_DATE? > <? $P_FROM_DATE? >

    This date of form source of report and setting is coming as this 2012/11/01 00:00:00.

    So now I need this in MY-DD-YYYY marker. I tried like this..? param@begin:P_FROM_DATE? > <? $format - date: P_FROM_DATE; ' DD-MON-YYYY '? >

    but its giving error. Can someone pls how to convert to the format of date custom.

    Thanks and greetings
    Srikkanth.M

    Problem solved.

    REF this link

    Date Format of XML

  • How to convert the Date 2010 - 02-20T 00: 00:00.00 - format 00:00

    Hello

    In my application, I have a single field. Here the user can select the date by using the calendar dropdown.

    While sunmitting the PDf I want to spend the date like this format 2010-02-20 T 00: 00:00.00 - 00:00

    everyone is to have an idea.

    Concerning

    Moustapha

    Try this... Language is FormCalc.

    A hidden text field and place the code in the output of the Date below field event.

    Replace Date() and Time() below with the appropriate field values.

    $

    = Concat (Num2Date (Date (), "YYYY-MM-DD"), "T", Num2Time (Time (), 'HH'));

    Thank you

    Srini

  • How to set the date and time on my HP Officejet pro 8600 more?

    How to set the date and time on my HP officejet pro 8600 more?  It just on a printed journal Jan-oo-oo fax shows 00:00 AM.  There are no instructions on how to change this.  I need proof that I sent a fax to a certain date and time.  Help, please.  Thank you

    Hello

    Below are the steps to set the Date and time for your device:

    1. On the Control Panel, press the right arrow key ( ), press Setup ( ).

  • How to set the Date and time on a remote target in Measurement &amp; Automation Explorer (MAX)?

    Hello

    I'm trying to follow the steps described in the following link:

    How to set the Date and time on a remote target in Measurement & Automation Explorer (MAX)?

    It is said

    The software on the target currently supports only the time zoneand deletes the old files?

    I need set the date and time

    and remove all the old unwanted files

    the calendar was gray does not allow me to change the current date.

    Anyone know how to change

    Hi all!

    According to this the below Knowledge Base article, Remote Configuration System Support must be installed on the target for time settings to change in MAX.

    http://digital.NI.com/public.nsf/allkb/FAB0EC4D6E5EE0F386257738005733A3?OpenDocument&MeTC=max_MAXDat...

    If you don't know what version of the system supported remote Configuration software that you have installed on your device target, it is likely that it is not yet installed. Add this software by clicking below your target to the MAX software option and selecting "Add/Remove Software". This is where you will install the System Configuration Remote Support software.

    Please let us know if you have any questions!

  • How to format the SD card?

    Android 4.0 will erase all data on my phone, right?

    I want to format the SD card, too, because some setting or cache is stored on it as well.  When and how should I do this?

    Here's how to format the sd card
    Settings > storage > unmount sd card > remove sd card

    Don't forget to mark the right answer and the useful answer

  • How to convert the date in milliseconds?

    Hi all

    Can I know how to convert the date in milliseconds?

    My current datetime like this Formate

    QDateTime::currentDateTime (m:System.NET.SocketAddress.ToString ("MMMM dd, yyyy HH"))

    Seconds since January 1, 1970

    http://Qt-project.org/doc/Qt-4.8/QDateTime.html#toTime_t

    Sinds milliseconds January 1, 1970

    http://Qt-project.org/doc/Qt-4.8/QDateTime.html#toMSecsSinceEpoch

  • How to get the Date, month, year of the DateTimePicker

    Hi, I am using the DateTimePicker.

    There are several question about this command:

    1. how to get the Date, month and year?

    -With the help of myDateTime.value, I get this string ' Wed May 08 14:45 ICT 2013 '-> I have to manually analyze this? Because I need in format yyyy/mm/dd. Or can set the format of dateTimePicker.value?

    2 format on dateTimePicker self (on the user interface) is d/m/YY, I can't change to another format?

    Thank you

    dateTimePicker.value return a QDateTime not a string.

    https://developer.BlackBerry.com/Cascades/reference/bb__cascades__datetimepicker.html#property-value

    See more:

    https://developer.BlackBerry.com/Cascades/reference/QDateTime.html#date

    https://developer.BlackBerry.com/Cascades/reference/QDate.html

    You can get

    day = dateTimePicker.value.date().day()
    month = dateTimePicker.value.date().month()
    year= dateTimePicker.value.date().year()
    dateYYYYMMDD = dateTimePicker.value.date().toString(Qt::ISODate)
    dateYYYYMMDD2 = dateTimePicker.value.date().toString("YYYY/MM/DD")
    dateYYYYMMDD3 = dateTimePicker.value.toString("YYYY/MM/DD")
    

Maybe you are looking for

  • Installation of WXP and VAP - FN brightness keys don't work

    Hello All the sources I found State that the package of value added cannot be installed on XP. I was able to rewrite the installation file to install VAP and its required files without problem.I am able to run the programs and the function. The only

  • Equium M50: 2200BG WLan - unable to connect to the internet

    Equium M50 / wireless 2200BG Pro / Wireless eircomNETOPIA router 1642 4640 eircom Hello I have Aproblem with my wireless connection When I go to network connection I have 3 parts: 1-broadband: inside there is a connection to broadband in disconnected

  • Write to the spreadsheet does not work

    I compare a string that I enter in a text box, a string a .csv. If the string is found, the data is written to a file, but if the string is not found, other data should be written to another file, but nothing happens. I used the copy of the code that

  • How to make a bootable windows xp cd?

    Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: You have problems with programs Error messages Recent changes to your computer What you have already tried to solve the problem

  • Save an Xbox Avatar on my laptop

    I created a new avatar xbox on my computer windows 7 and you want to save it on my laptop but when I just lick on my avatar it just says stupid words "Silverlight". It gets annoying because I know but you can save it to your laptop on windows 10 wind