Add Row Number and use it to calculate other column

Hi,
I have below query which I am using to generate a report.
Select (count(I.Colour)*3) as TotLitres, (count( distinct P.description)) as NumOfMachine,
(count(I.Colour)*3)/(count( distinct P.description)) as AverageLiter,
DATEName(MONTH,ShipDate) + ' ' + convert(varchar,DATEPART(year, shipDate)) as [Loaded Date],
(count(I.Colour)*3)+ ((count(I.Colour)*3)/(count( distinct P.description)))* 4 as FutureSales
from DATATab I inner join Inktab P on I.SerialNum =P.SerialNum
where
I.Colour in ('Cyan','Magenta','Yellow','Black','Light Cyan','Light Magenta','Light Yellow','Light Black','Orange','White','Matte Black')
and I.ShipDate between dateadd(YY,-1,getdate()) and dateadd(YY,-1,dateadd(mm,6,getdate()))
group by DATEPART(year, shipDate),DATEName(MONTH,ShipDate),DATEPART(MONTH, shipDate)
order by DATEPART(year, shipDate),DATEPART(MONTH, shipDate)
Now I want to add two more columns to my select statement.
1. Row count
2. AverageLiter * Row count
Can someone please guide me on how i can achive that.
Thanks in advance .

select *,(v.Row*v.AverageLiter) as Calculatedvalue  from (
Select ROW_NUMBER() 
        OVER (ORDER BY [CreateDate]) AS Row, (count(I.Colour)*3) as TotLitres, (count( distinct P.description)) as NumOfMachine,
(count(I.Colour)*3)/(count( distinct P.description)) as AverageLiter,
DATEName(MONTH,ShipDate) + ' ' +  convert(varchar,DATEPART(year, shipDate)) as [Loaded Date],
(count(I.Colour)*3)+ ((count(I.Colour)*3)/(count( distinct P.description)))* 4 as FutureSales
from DATATab I inner join Inktab P on I.SerialNum =P.SerialNum 
where 
 I.Colour in ('Cyan','Magenta','Yellow','Black','Light Cyan','Light Magenta','Light Yellow','Light Black','Orange','White','Matte Black') 
and I.ShipDate between dateadd(YY,-1,getdate())   and dateadd(YY,-1,dateadd(mm,6,getdate()))  
group by DATEPART(year, shipDate),DATEName(MONTH,ShipDate),DATEPART(MONTH, shipDate)
 order by DATEPART(year, shipDate),DATEPART(MONTH, shipDate) ) v
please mark as answered if it helps :)

Similar Messages

  • How to add rows in tableview using javascipt

    Hi
    I had tableview and button in my page.If i click on the button one new row should be appended to the existing tableview.
    so , how to add rows in tableview using javascipt which are editable?
    Regards,
    Pydi.

    Hi,
      Javascript is client scripting language, which is mainly used for validations at the client side.
      To add new row using a HTMLB tag ucannot use javascript. Instead pass "visibleRowCount" variable to a abap variable and add the variable on every button click.. that wil increase the visible row count.
    Also the size of the table view is the size of the itnernal table, so append a blank like to the internal table or insert it at the top.
    If you are not using HTMLB tags and using simple HTML tags u can always add a row using java script.
    Regards
    Imran.

  • HELP. 3 years ago I purchased cs3. I had troubles with registering the serial number and used my university's suite instead, and (stupidly) did not sort it out. I am now wanting to subscribe to the online creative cloud with my cs3 discount. Is there any

    HELP. 3 years ago I purchased cs3. I had troubles with registering the serial number and used my university's suite instead, and (stupidly) did not sort it out. I am now wanting to subscribe to the online creative cloud with my cs3 discount. Is there any way to find / prove that I had purchased cs3 and locate a serial number? On my Adobe account it does not show my purchase of cs3 (I am guessing because of the trouble with registering my serial number). I have moved house 3 times since the purchase and am unable to locate the packaging or disk. Is there any way to prove my purchase without any serial number or showing under my Adobe account? Please help! Thanks

    The CS3 discount offer is only for retail online product, it does not include education or volume license purchases. Refer to Terms and Conditions | Adobe
    To check whether you had retail CS3 purchase, we need proof of purchase as well as serial number, without which the issue can not be resolved.
    Regards
    Rajshree

  • I changed my number along with my sim card and imessage will not recognize my new number. how can i have imessage forget my old number and use my new number?

    i changed my number along with my sim card and imessage will not recognize my new number. how can i have imessage forget my old number and use my new number?
    i have tried signing out of imessage and signing back in. (when i do that and am asked to select my email adress, i see my new number but it is greyed out and i cant select it)

    But under send and receive, my old number is still displayed while my new number isn't.

  • My dad has an upgrade with his phone number, can I preorder the iPhone 5s with his number and use it with my phone number?

    I want to preorder the iPhone 5s. My personal phone number is not eligible for an upgrade yet, but my day's phone number is. He says that I can use his upgrade. On September 20, 2013 when the online preorder begins, am I able to preorder a phone for myself with my dads number and use it with my own number? How does it all work?

    Most carriers will allow you to swap phones between numbers without a problem. Swapping will not change the contract on the number that the phone was ordered for. Nor will it affect eligibility for future upgrades. Of course the "swap" will normally need to be done with phones on the same carrier and is probably easier to do when on the same account.
    I do this every year, or rather every other year. I am the techie, my wife not so much. So when the new iPhone comes out, I get it for which ever number is eligible for upgrade and have it activated to my number and then activitate my old phone to her number. I usually go to the phone company store (AT&T in my case) as they have new sims on hand and usually need to use at least one.

  • Tab Form LOV uses one of the other columns in that report.

    Hi All.
    i created a Tabular Form using the Wizard.
    i want to change one of the columns in the report to be an LOV.
    the LOV has a WHERE that uses one of the other columns in that report.
    i tried to do something like that:
    SELECT <display_value>, <return_value>
    FROM <some_table>
    WHERE <my_column> = #ANOTHER_COLUMN_FROM_REPORT#
    it doesnt work...
    anyone know how to do it?
    thanks in advance
    Alberto

    See
    http://htmldb.oracle.com/pls/otn/f?p=18326:54:::::P54_ID:1282
    Also see the discussion at
    http://forums.oracle.com/forums/thread.jspa?messageID=1222153

  • Advance Table - Add Row button and coloumn issue

    Hi all,
    I have created Advanced Table wth four coloumns.
    for two columns item style as messagtextinput and the rest are same as DATE.
    But when the page is rendering the table columns shows as messagestyletext , which means messagetextinput style item is not appearing.
    Kindly help me if am missed anything wrong.
    and also can u help me to create add row button featurs in advance table
    Thanks in advance.
    Senthur

    Senthur,
    I hv done this using row status initialised.I couldnt get the above lines.
    I have another doubt also. In Advanced table there is coloumn header, is there any Row header.There is nothing as such RowHeader. Let me know ur exact requirement.
    Name age salary
    empid1 xxx 21 100
    empid2 yyy 22 200Create a VO which return the above attributes and attach the same to the Adavanced Table Bean.
    Regards,
    Gyan

  • Add jar files and use those classes at the runtime

    Hi All,
    I need to add some jar files at the runtime depends on which the user selects where the jar file is located and i need to import those classes in other class for some functionalities . I could add jar files by using the URLClassLoader and Class.forName("myjar.myclassname") is also succeeded and i have no clue how to use those classes with in the jar file as i couldn't import those classes also in the source because the jar files are being added at the runtime(This leads to class not found exception at the compile time).
    I had found a complicated way of using those classes after being added at the run time as below.
       Class clazz = Class.forName(myClass);
                final Method method = clazz.getDeclaredMethod(requiredMethod, new Class[]{URL.class});
                final Object returned = method.invoke(clazz.newInstance(), new Object[]{request}); but, its really pain to use in this way in all the places.
    Does any of you have simpler suggestions on how to achieve this?
    Thanks,
    Venky.

    Thanks jschell. Yes, you are right. I had found that using reflection API is the only way to load classes at the run time. But according to our application using reflection makes the application little complex, so while start of the application or during other modifications, i am overwriting my jar file to the latest one using FileChannel class as below
          FileChannel ic = new FileInputStream("new.jar").getChannel();
          FileChannel oc = new FileOutputStream("old.jar").getChannel();
          ic.transferTo(0, ic.size(), oc);
          ic.close();
          oc.close();After this code is executed, our application totally uses the new jar file.It is little fast than using reflection. Is this a good idea?

  • How to modify the port number and use subdomains

    Couple of things ...
    1 - default port for installation is on 7777 and 7778. Would it be possible to run everything on port 80? I would like to hide the port number and not have people type in http://domain.com:7778
    2 - how can we use subdomains for certain services? For example, webmail should be http://webmail.domain.com and the RTC should be http://conference.biztech.com
    thx

    we're using OCS both inside and outside our network.
    I had my dba modify the port so now everything runs on port 80. However, I dont know how to get virtualhost to work correctly.
    conference.domain.com -> RTC piece
    webmail.domain.com -> webmail piece
    i.e....

  • How to run different programs and use their output in other programs

    Dear java members,
    I am trying to figure out how to get data from a file, database, or program and use that information in another
    program. Can you help please?
    I have looked through several texts and while the information is there somewhere I have not found the specific
    capabilities or examples that explain how to do this.
    I want to learn how to do this with objects.
    The specific applications I am working with are the GIS (Geographic Information System) suite of ESRI products
    such as ArcInfo and ArcView.
    I am working with simulators for hydrologeology (ground water) and other geophysical phenomenae. Programs for
    decisions and assessment of probability such as found in geostatistical analyses packages. Drawing programs
    and data manipulation programs such as spreadsheets in windows and scripting languages found in most Unix
    packages.
    I want to be proprietary platform free! I want to be accessing apps and or data wherever they are and in
    whichever form they are in or best used.
    Web techniques and protocols are where I think most of my effort will be focused.
    One of the mediums (media) that I expect to use a lot is XML.
    If I can find a simplified (generalized) explanation how this is done and how the parts fit together through and or
    with objects. If I can find references to texts and examples I will be very appreciative and very much less
    confused.
    I am interested in using the Java programming language.
    Thank you
    ctavares1

    Hello ctavares1,
    I am not quite sure that I understand what you are trying to do. The programs that you mention: ArcInfo and ArcView, are they stand alone, native, platform dependent applications? Or are they written in Java? It sounds like there are stand alone, native, platform dependent applications, that write their output to either a file or a database.
    The other piece that is puzzling me is: Do you intend to write an Applet or a Java Application? This is important because Java places several restrictions on what an Applet can do.
    There is also the question of how the data is produced. Is it produced all at once in batch or is it produced a little at a time in real time?
    These and other questions will need to be answered before you can begin designing your application. There are many tutorials dealing with opening a file or database and manipulating that data from an Applet or a Java Application, but it is a different matter all together getting data from an application.
    Here are a few tutorials on File I/O and JDBC:
    http://java.sun.com/docs/books/tutorial/jdbc/index.html
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    -Merwyn,
    Developer Technical Support,
    http://www.sun.com/developers/support.

  • Creating a master table and using it to populate other tables.

    Hi everyone.
    I am a novice at using Numbers and I need some direction.
    I am looking to create a master table with information for our summer camp. This table will include vital information such as name, address, etc. along with cabin assignments, tuitions received, and more.
    We will separate this information into smaller tables that different portions of that master table for specific use. Such as: names and addresses for leaders, names and tuitions for registration, etc.
    My goal is to type the information into the master table and have it update the other tables automatically. Can someone direct me how to format the master and sub tables so that this is possible?
    I would greatly appreciate it and it will greatly reduce the record-keeping time for our camp.
    Thank You!
    Roy

    Hi Roy,
    Welcome to the Numbers discussions. You are giving us a tall order, especially when we don't know your level of experience in programming spreadsheets.
    Here are a couple of basics to start the conversation...
    In normal spreadsheet programming, we Pull data from one location into another, we don't Push it or Send it. This should help you to understand that the hard work is done in the sub tables, not the master.
    You will use LOOKUP functions to pull the data to your sub tables. Download the Numbers User Guide and the Formulas and Functions User Guide and read up on them.
    In your master table, make sure you have one column that uniquely identifies each participant so it will be easy to reference that person in your sub tables.
    Regards,
    Jerry

  • Can we able to purchase ipod touch in US and use it in some other country? will there be any issues?

    Have anyone tried purchasing in US and using it in India?

    You shouldn't have any problems recharging if you have the correct recepticle conversion plug for the AC adapter you purchase in the US. I've used and charged my IPOD touch 3G in US, UK, China, Israel, Australia, Greece, Hungary, Czech Republic and several other countries including ships.

  • OBIEE 10g How ADD new report and use outer join

    Hi,
    I have to add a new report that use a new view...(just created in db)
    I'm new in OBIEE.. can you explain how can i do it?
    Actually:
    1. I opened administrator tool and import new view (and created an alias) in physical
    2. I built a logical table in BMM
    3. I built a new presentation table in presentation
    problem: the table in BMM have yellow icon like a fact table.. why??
    can you explain me what i have to do?
    thank you
    Edited by: 1006028 on 15-mag-2013 2.54

    By default OBIEE 10g considers a table as fact table that is dragged from physical to BMM layer. That's why you see the yellow color icon.
    If it is a dimension table, you will have to join this table with a fact table in BMM layer. After this the yellow color icon will go away.
    Pls mark correct/helpful.

  • Add vendor number and vendor name to the SAP Standard CO/PS Line item repor

    Hi
    how i can post PS commitment line items and cost center and orders commitment line items
    The SAP standard reports are:
    CJI5 PS Commitment Line items
    KSB2 Cost Centre Commitment Line Items
    KOB1 Orders Actual Line Items
    KOB2 Orders Commitment Line Items.
    give me suggestion for above tr. codes
    Regards
    nreddy

    I dont uderstand completely, your subject says you want to add vendor field, but your message body says "how i can post PS commitment line items and cost center and orders commitment line items" . What is your requirement?

  • Querying on a value and using that to pull other data in the same query

    I am having some issues pulling the correct data in a query. There is a table that houses application decision data that has a certain decision code in it, WA, for a particular population of applicants. These applicants also may have other records in the same table with different decision codes. Some applicants do NOT have WA as a decision code at all. What I need to do is pull anyone whose maximum sequence number in the table is associated with the WA decision code, then list all other decision codes that are also associated with the same applicant. These do not necessarily need pivoted, so long as I can pull all the records for a person whose highest sequence number is associated with WA and all of the other decision codes for that applicant for the same term code and application number also appear as rows in the output.
    I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them.
    DROP TABLE SARAPPD;
    CREATE TABLE SARAPPD
    (PIDM              NUMBER(8),
    TERM_CODE_ENTRY   VARCHAR2(6 CHAR),
    APDC_CODE         VARCHAR2(2 CHAR),
    APPL_NO        NUMBER(2),
    SEQ_NO             NUMBER(2));
    INSERT INTO SARAPPD VALUES (12345,'201280','WA',1,4);
    INSERT INTO SARAPPD VALUES (12345,'201280','RE',1,3);
    INSERT INTO SARAPPD VALUES (12345,'201280','AC',1,2);
    INSERT INTO SARAPPD VALUES (23456,'201280','RE',1,2);
    INSERT INTO SARAPPD VALUES (23456,'201280','WA',1,3);
    INSERT INTO SARAPPD VALUES (23456,'201280','SC',1,1);
    INSERT INTO SARAPPD VALUES (34567,'201280','AC',1,1);
    INSERT INTO SARAPPD VALUES (45678,'201210','AC',2,1);
    INSERT INTO SARAPPD VALUES (45678,'201280','AC',1,2);
    INSERT INTO SARAPPD VALUES (45678,'201280','WA',1,3);
    INSERT INTO SARAPPD VALUES (56789,'201210','SC',1,2);
    INSERT INTO SARAPPD VALUES (56789,'201210','WA',1,3);
    COMMIT;I have attempted to get the data with a query similar to the following:
    WITH CURR_ADMIT AS
          SELECT   C.SEQ_NO "CURR_ADMIT_SEQ_NO",
                            C.PIDM "CURR_ADMIT_PIDM",
                            C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
                            C.APDC_CODE "CURR_ADMIT_APDC",
                            C.APPL_NO "CURR_ADMIT_APPNO"
                              FROM SARAPPD C
                              WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
                              AND C.APDC_CODE='WA'
                             AND C.SEQ_NO=(select MAX(d.seq_no)
                                                   FROM   sarappd d
                                                   WHERE   d.pidm = C.pidm
                                                   AND d.term_code_entry = C._term_code_entry)
    select sarappd.pidm,
           sarappd.term_code_entry,
           sarappd.apdc_code,
           curr_admit.CURR_ADMIT_SEQ_NO,
           sarappd.appl_no,
           sarappd.seq_no
    from sarappd,curr_admit
    WHERE sarappd.pidm=curr_admit.PIDM
    and sarappd.term_code_entry=curr_admit.TERM_CODE_ENTRY
    AND sarappd.appl_no=curr_admit.APPL_NOIt pulls the people who have WA decision codes, but does not include any other records if there are other decision codes. I have gone into the user front end of the database and verified the information. What is in the output is correct, but it doesn't have other decision codes for that person for the same term and application number.
    Thanks in advance for any assistance that you might be able to provide. I am doing the best I can to describe what I need.
    Michelle Craig
    Data Coordinator
    Admissions Operations and Transfer Systems
    Kent State University

    Hi, Michelle,
    903509 wrote:
    I do not have the rights in Oracle to create tables, so please pardon if this code to make the table is incorrect or doesn't show up here as code. This is not the entire SARAPPD table framework, just the pertinent columns, along with some data to put in them. You really ought to get the necessary privileges, in a schema that doesn't have the power to do much harm, in a development database. If you're expected to develop code, you need to be able to fabricate test data.
    Until you get those privileges, you can post sample data in the form of a WITH clause, like this:
    WITH     sarappd    AS
         SELECT 12345 AS pidm, '201280' AS term_code_entry, 'WA' AS apdc_code , 1 AS appl_no, 4 AS seq_no     FROM dual UNION ALL
         SELECT 12345,           '201280',                    'RE',               1,             3                 FROM dual UNION ALL
         SELECT 12345,           '201280',                  'AC',            1,          2               FROM dual UNION ALL
    ... I have attempted to get the data with a query similar to the following:
    WITH CURR_ADMIT AS
          SELECT   C.SEQ_NO "CURR_ADMIT_SEQ_NO",
    C.PIDM "CURR_ADMIT_PIDM",
    C.TERM_CODE_ENTRY "CURR_ADMIT_TERM",
    C.APDC_CODE "CURR_ADMIT_APDC",
    C.APPL_NO "CURR_ADMIT_APPNO"
    FROM SARAPPD C
    WHERE C.TERM_CODE_ENTRY IN ('201210','201280')
    AND C.APDC_CODE='WA'
    AND C.SEQ_NO=(select MAX(d.seq_no)
    FROM   sarappd d
    WHERE   d.pidm = C.pidm
    AND d.term_code_entry = C._term_code_entry)
    Are you sure this is what you're actually running? There are errors. such as referencing a column called termcode_entry (starting with an underscore) at the end of the fragment above. Make sure what you post is accurate.
    Here's one way to do what you requested
    WITH     got_last_values  AS
         SELECT  sarappd.*     -- or list all the columns you want
         ,     FIRST_VALUE (seq_no)    OVER ( PARTITION BY  pidm
                                        ORDER BY      seq_no     DESC
                                  )           AS last_seq_no
         ,     FIRST_VALUE (apdc_code) OVER ( PARTITION BY  pidm
                                        ORDER BY      seq_no     DESC
                                  )           AS last_apdc_code
         FROM    sarappd
         WHERE     term_code_entry     IN ( '201210'
                           , '201280'
    SELECT     pidm
    ,     term_code_entry
    ,     apdc_code
    ,     last_seq_no
    ,     appl_no
    ,     seq_no
    FROM     got_last_values
    WHERE     last_apdc_code     = 'WA'
    ;Don't forget to post the results you want from the sample data given.
    This is the output I get from the sample data you posted:
    `     PIDM TERM_C AP LAST_SEQ_NO    APPL_NO     SEQ_NO
         23456 201280 WA           3          1          3
         23456 201280 RE           3          1          2
         23456 201280 SC           3          1          1
         45678 201280 WA           3          1          3
         45678 201280 AC           3          1          2
         45678 201210 AC           3          2          1
         56789 201210 WA           3          1          3
         56789 201210 SC           3          1          2I assume that the combination (pidm, seq_no) is unique.
    There's an analytic LAST_VALUE function as well as FIRST_VALUE. It's simpler (if less intuitive) to use FIRST_VALUE in this problem because of the default windowing in analytic functions that have an ORDER BY clause.

Maybe you are looking for

  • Issue Regarding Payment recived by cheque

    Dear all Business Process: Sales team pass the Invoice Entry & Billing Entry. Collection of Cheque from Customer is also done by the Sales Team. After that they maintain an Excel Sheet containing Bill Number & Cheque details and send it to the Financ

  • I'm using yahoo email on firefox but cannot download or save doc file attachments

    Emails that I have received on my yahoo account contain attachments, saved as word documents or powerpoint or pdf files. Today, when I tried to download these files, the daownloading software could not recognise the file format in any of the files (I

  • Strangeness with payment. two plans.

    strangeness with payment. somehow create two annual plan. write programs that I have one day to the end of the subscription, even though I paid for a month yesterday. you have Russian support? where you can call?

  • Inserting blank pages.

    Oh my!  Have been to the manual but since I am a Sr. Citizen, its information was a little (well, a lot) over my greying locks.  Want to add a blank page in a continuous text document (word processing) with photos thrown in from iphoto.  Not locked,

  • Loading text by XML

    Hi: I am very new to XML so I would like to know if someone could help me, this should be very simple. I have a textbox in my flash movie that will display the main text (only a short paragraph); my client wants that text to be loaded by XML but I do