Is it possible to multiply the result of a count function by another column

Hello,
I need to generate an invoice for the amount of nursery sessions a given child has attended. I can get the amount of sessions using this query:
select COUNT(s.session_id), cr.child_id
from sessions s, child_register cr
where s.session_id = cr.session_id
and cr.child_id = 'C110001'
group by cr.child_id;
Which outputs:
2     C110001
I can't figure out how to multiply the result of COUNT(s.session_id) by a row in the session table called srate (which is a number, 20)
Here are my attempts:
select COUNT(s.session_id) * s.rate, cr.child_id
from sessions s, child_register cr
where s.session_id = cr.session_id
and cr.child_id = 'C110001'
group by cr.child_id;
I get an error 'Not a group by expression which makes sense
Then I tried:
select COUNT(s.session_id) * s.rate AS total, cr.child_id
from sessions s, child_register cr
where s.session_id = cr.session_id
and cr.child_id = 'C110001'
group by total;
Error 'total' not a valid identifier, Wrapping the COUNT(s.session_id) * s.rate in parentheses gives me the same error.
I'm sure it's something blatantly obvious :(
Any help very much appreciated as always,
Mike

Why don't you head over to the SQL & PL/SQL forum here...
PL/SQL
Expect to be asked to provide create table and inserts with sample data though, as well as to wrap your code in {noformat}{noformat} tags to make it more readable and preserve formatting!
Cheers
Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • I have an iphone 3gs, i bought it with the carrier Orange in Mauritius and i would like to know if it is possible to unlock the iphone so that i can use another carrier.

    i have an iphone 3gs, i bought it with the carrier Orange in Mauritius and i would like to know if it is possible to unlock the iphone so that i can use another carrier. thanks

    Only the carrier can authorise unlocking. You need to contact them.

  • Is it possible to name the results table.

    Hi, I'm new to java and have hit a brick wall devloping a GUI which access a SAPDB database.
    They layout of the GUI is:
    have a awt lists in card layout, which is populated with the results of a SQL query to table REGION.
    However the number of results returned can be greater then 1Mill. To minimise the mem useage, i'm using the ResultSet absolute(), first() etc methods to collect and display small chunks of the data, for the different card in the gui. This works fine :)
    However, the user is able to select an item from the list to perform a new query, which the results a presented in a dialog box, not dependent on the parent frame. Works :)
    But, when the user (I) try to move anothe card in the parent frame I get this error:
    SAP DBTech JDBC: Object is closed
    com.sap.dbtech.jdbc.exceptions.ObjectIsClosedException: SAP DBTech JDBC: Object is closed
    at com.sap.dbtech.jdbc.ConnectionItem.assertOpen(ConnectionItem.java:54)
    at com.sap.dbtech.jdbc.ResultSetSapDB.beforeFirst(ResultSetSapDB.java:177)
    at blastDb.Table.getResultSetSize(Table.java:205)
    at blastDb.Table.setCursor(Table.java:227)
    at ViewDatabase$RegionPanel.setRegionList(ViewDatabase.java:354)
    at ViewDatabase$TabPanel.showRegionList(ViewDatabase.java:180)
    at ViewDatabase$TabButtonListener.actionPerformed(ViewDatabase.java:289)
    at java.awt.Button.processActionEvent(Button.java:381)
    at java.awt.Button.processEvent(Button.java:350)
    at java.awt.Component.dispatchEventImpl(Component.java:3526)
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:191)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
    After some reading I have come up with this hypothesis:
    In the parent frame there is the object (class) RegionTable, which contains the ResultSet (rsR) of the sql query generated by it.
    In the dialog box there is the object (class) ProteinTable which also contains the ResultsSet (rsP) of the sql query generated by it.
    So when RegionTable querys the database the rsR points to the results table in the SAPDB. All good.
    However when ProteinTable querys the database, rsR closes and rsP is valid ie. points to the results table in the SAPDB.
    Thus after the second query RegionTable.rsR is unable to collect the results of its query. BAD :(
    From what i have read, if the results table is named for the first query, the second call which results table is named something diff then rsR will not close, as the results table is not destroyed, thus rsR can read it's results after the second qury.
    This problems occours when the objects share the same connection or diff connections.
    As far as I'm aware i'm using JDBC 1.2 drivers and SAPDB latest build.
    I know i could hold the results in a view, but that requies more coding, being able to name the results table in the SAPDB make it alot easier.
    So my question is:
    1. Are my assumptions correct??
    2. is there a SQL statement to name the results table for a given query?
    From SAPDB:
    A result table name identifies a result table (see table).
    Syntax
    <result_table_name> ::= <identifier>
    And I've got no idea what is beging impiled beyond that it is possible to name a results table. Obtained from :
    http://www.sapdb.org/htmhelp/da/ed9036dfe4b903e10000009b38f889/frameset.htm
    If anyone can help, that would be fantastic!!!
    Cheers
    fauxn

    I've check the code, when the dialog box is opened a new connection is made, and i still get the same error:
    SAP DBTech JDBC: Object is closed
    com.sap.dbtech.jdbc.exceptions.ObjectIsClosedException: SAP DBTech
    JDBC: Object is closed
    at com.sap.dbtech.jdbc.ConnectionItem.assertOpen(Connection
    Item.java:54)
    at com.sap.dbtech.jdbc.ResultSetSapDB.beforeFirst(ResultSet
    SapDB.java:177)
    at blastDb.Table.getResultSetSize(Table.java:205)
    at blastDb.Table.setCursor(Table.java:227)
    at ViewDatabase$RegionPanel.setRegionList(ViewDatabase.java
    :354)
    at ViewDatabase$TabPanel.showRegionList(ViewDatabase.java:1
    80)
    at ViewDatabase$TabButtonListener.actionPerformed(ViewDatab
    ase.java:289)
    at java.awt.Button.processActionEvent(Button.java:381)
    at java.awt.Button.processEvent(Button.java:350)
    at java.awt.Component.dispatchEventImpl(Component.java:3526
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Ev
    entDispatchThread.java:191)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Even
    tDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThr
    ead.java:138)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThr
    ead.java:130)
    at java.awt.EventDispatchThread.run(EventDispatchThread.jav
    a:98)
    when i ask rsR to collect the results from it's query.
    Dosen't make sence, unless its they way I'm implementint the GUI???
    I'll look into the JDBC driver bug.
    Cheers

  • Have to reset the Apple TV each time I open it. Is it possible it is the result of recent transfer to iCloud?

    Each morning when I open CalmRadio on my Surround System which come from iTune through Apple TV  I have to reset the Apple TV to get the signal through. I tought it was the result of a recent change of my router but I just remember that I have installed iCloud recently.  Would it be possible that would be the reason of the necessity to reset apple TV every morning?  Thanks.

    I'd say your router, iCloud hasn't caused me any problems. It may be settings or interference.
    Interference can be caused by other networks in the neighbourhood or from household electrical items.
    You can download and install iStumbler (NetStumbler for windows users) to help you see which channels are used by neighbouring networks so that you can avoid them, but iStumbler will not see household items.
    Refer to your router manual for instructions on changing your wifi channel.
    There are other types of problems that can affect networks, but this is by far the most common, hence worth mentioning first.

  • Is it possible to put the results from a query in a variable to use in the bean class?

    Hello, I'm using JDeveloper 12.1.2.0.0
    I would like to keep the result of my queries (the method i created in the AppModule) in a RichTable or other type of variable so i can have the results stored and i don't have to do unnecessary queries after. I don't think the query is the problem but keeping the results.
    I've tried to do that by using this:
        public String testVFactSales(String conditions) {
            PreparedStatement query = getDBTransaction().createPreparedStatement("" + "select * from v_fact_sales " + conditions, 0);
            //ResultSet rs;
            ResultSet result;
            //RichTable result;
            //String result = null;
            try {
                //query.setString(1, conditions);
                // query.execute();
                query.execute();
                result = query.getGeneratedKeys();
                query.close();
                System.out.println("Result: " + result.toString());
                return result.toString();
            } catch (SQLException e) {
                e.printStackTrace();
            return "";
    As you can see, i've already tried some solutions but so far i only get errors (cannot convert or null exception, when i try to put the result in a richtable in my bean class)
    Any ideas?
    This is very important for me, since it would improve the performance of my project a lot.
    Regards,
    Frederico.

    Hey Arunkumar,
    I came to this conclusion since i'm using binding variables with my where clauses.
    I've measured the time and i get really bad time responses.
    This is my main table query, where all the others selections will be filter the search in this table:
    SELECT VFactSalesNew.N_SALES,                              
           VFactSalesNew.QUANTITY,                              
           VFactSalesNew.PRICE,                               ,                              
           VFactSalesNew.FK_STORE,                              
           VFactSalesNew.ID_ANO,                              
           VFactSalesNew.QUARTER   
    FROM V_FACT_SALES_NEW VFactSalesNew                              
    WHERE                                          
    ((nvl(:var_dimCoin,'0') ='0' OR FK_COIN IN (select * from THE(select cast( in_list(:var_dimCoin) as mytableType ) from dual ) a) )                                                   
    AND                                                 
    (nvl(:var_dimProduct,'0') ='0' OR FK_PRODUCT IN (select * from THE(select cast( in_list(:var_dimProduct) as mytableType ) from dual ) a) )                                                  
    AND                                                 
    (nvl(:var_dimCustomer,'0') ='0' OR FK_CUSTOMER IN (select * from THE(select cast( in_list(:var_dimCustomer) as mytableType ) from dual ) a) )                                                 
    AND                                                 
    (nvl(:var_dimStore,'0') ='0' OR FK_STORE IN (select * from THE(select cast( in_list(:var_dimStore) as mytableType ) from dual ) a) )                                                
    AND                                                 
    (nvl(:var_dimSeller,'0') ='0' OR FK_SELLER IN (select * from THE(select cast( in_list(:var_dimSeller) as mytableType ) from dual ) a) )                                                  
    AND                                                 
    (nvl(:var_dimProject,'0') ='0' OR FK_PROJECT IN (select * from THE(select cast( in_list(:var_dimProject) as mytableType ) from dual ) a) )                                                  
    AND                                                 
    (nvl(:var_ano, '0') ='0' OR ID_ANO IN (select * from THE(select cast( in_list(:var_ano) as mytableType ) from dual ) a) )                                                  
    AND                                                 
    (nvl(:var_treemap,'0') ='0' OR PK_REGION IN (select * from THE(select cast( in_list(:var_treemap) as mytableType ) from dual ) a) )                                                  

  • Is it possible to have the result from webservices with oracle8i

    hi,
    i call webservices MS .net with package utl_http under oracle 8i.
    exemple:
    DECLARE
    x utl_http.html_pieces;
    msg varchar2(12);
    BEGIN
    x := utl_http.request_pieces('http://localhost/ServiceNotification/Notification.asmx/NotifT?messagetmp=' || msg);
    END;
    I don't know how to have a result from a webservices!
    thanks for helping me.

    While the following paper is Oracle9i DB specific, conceptually, what is done should work with Oracle8i.
    Bear in mind that the use of XMLType is specific to Oracle9i DB R2 so if you were to follow the example, you would have to use varchars and probably acept the result into the PL/SQL XML Parser. See:
    http://otn.oracle.com/tech/webservices/htdocs/samples/dbwebservice/DBWebServices.html
    Mike.

  • What is the possibility of changing the result of asoftware wth human mind?

    I'm wonder that is there any research done over the connection between Subnatural gifted people and the computers?!
    For example can someone who has such gifts change the result of the software direction just with his gifts?
    Some of them who such gifts have, they may get their wishes in real world physically just with desiring those things.
    just wondering... maybe someone heard such researches...
    greetings,

    Hi,
    I just add another method to diagnose your problem. You can try to use xbootmgr to collect a boot trace of your system.
    Refer to the link below for more details about the trace steps:
    http://blogs.technet.com/b/jeff_stokes/archive/2012/09/17/how-to-collect-a-good-boot-trace-on-windows-7.aspx
    Roger Lu
    TechNet Community Support

  • Is it possible to multiply the content of an array by a constant numeric.

    Hi,
    I am using Universal library to read a voltage from a DAQ device, and it seems the reading function is putting it into an 1-D array then into a graph.
    I need to get this voltage and multiply by a number and could not do that as it is in array format.
    How would I be able to multiply the array content by a constant numeric?
    Thanks
    Solved!
    Go to Solution.

    Hi,
    Thanks for the reply, did not work, I have attached an image illustrating it.

  • Using the results of one recordset to filter another.

    Hi
    I have a dynamically generated web page that uses a recordset to gather most of the relevant information that is needed on it. However, what i need to do is create a second record set on the same page and filter that second recordset using one of the results generated from the first recordset. The problem that i am having is that the first recordset displays its information as an echo <?php echo $row_Recordset1['move_type']; ?> but i obviously cannot use this echo code in the filter for the second recordset, the code obviously needs tweaking but i am not sure how.
    If it were as simple as copy and paste the query i would need for the recordset2 is as follows but i am unsure how to code the echo from the first recordset. I am well aware that the following code could never work but i hope it works as simplified example of my intention.
    SELECT ID, move_name, catagory_link_path, move_type, mem_on_off
    FROM moves
    WHERE move_type = <?php echo $row_Recordset1['move_type']; ?>
    ORDER BY move_name ASC
    Any help would be appreciated

    I can think of two ways this can be done. One way, (which may or may not be appropriate in your case) is to use an INNER JOIN. Here is an example:
    $presenterset1=mysql_query("SELECT * FROM presenters INNER JOIN presenters_course USING (presenter_id) WHERE course_id='$course_id' ORDER BY presenter_rank");
    Do a search for tutorials on INNER JOIN for information about how to use it.
    Another possible solution is to nest one SQL statement within the result of another: like this:
    $sql1=mysql_query("SELECT one, two, three from table1 WHERE one='$one'");
    while ($result1=mysql_fetch_assoc($sql1)){
    extract ($result1);
    $sql2=mysql_query("SELECT apple, orange, pear from table2 WHERE fruit='$three'");
    while ($result2=mysql_fetch_assoc($sql2)){
    extract ($result2);
    echo "$apple and $orange" and $pear<br/>";

  • Count function on months column gives wrong result

    Hi,
    I am on OBIEE 11.1.1.7.150120.
    I used the count function on the month column and rather than getting 12 as the answer i get 365. (i used a filter on the year column to restrict it to one year)
    How could this happen?
    Any help would be appreciated.

    I was able to get the answer as 12 on the month column in the Dim_Time using the count distinct.
    The main reason i was trying this is because i have a VALUE column in VIew_A. I am trying to sum the values of these, but when i use the sum function, the output is quite huge and wrong. I dosen't match with the monthly figures.
    For eg:
    Month
    Income Cost
    JAN
    186.96
    FEB
    309.29
    MAR
    246.82
    APR
    247.95
    998.76
    1,462.74
    MAY
    160.27
    645.60
    1,643.84
    JUN
    172.19
    693.61
    927.12
    JUL
    150.27
    605.32
    855.89
    AUG
    133.61
    483.66
    538.20
    789.22
    SEP
    144.56
    412.42
    582.34
    824.84
    OCT
    264.96
    315.66
    364.00
    631.32
    1,067.32
    1,466.22
    NOV
    240.39
    832.10
    968.32
    1,058.73
    1,638.38
    DEC
    215.81
    857.30
    869.31
    24005.34
    But if i use the sum function on the Income/cost column, the value i get is
    C_MONTH
    SUM(INCOME_COST)
    JAN
    5,795.86
    FEB
    8,660.21
    MAR
    7,651.52
    APR
    81,283.62
    MAY
    75,941.13
    JUN
    53,787.67
    JUL
    49,955.96
    AUG
    60,285.39
    SEP
    58,924.80
    OCT
    127,394.01
    NOV
    142,137.76
    DEC
    60,215.18
    This just doesn't work out. I need the answer to be 24005 by using the sum function

  • Is it possible to get the caller object in a function call hierarchy ?

    Hi,
    I have a problem in hand for adding a new functionality to an existing code with MINIMAL code change. For this I need to get some extra information in a function call from its caller. And for this I do not want to change the signature of the method, as it requires a lot of code change. So I need to have a programming facility by which I can get the object from which the function was invoked. Some thing like "{code}this.CALLEROBJECT{code}".
    Please let me know whether we can achieve this in JAVA. I wonder if such a facility exists in any programming language...
    Thanks in advance.
    Regards
    Joby

    No.
    Youd have to buy it Germany or see if an Apple Authrorized reseller in Singapore could order you the keyboard.

  • Is it possible to change the location of Current Oracle Binaries to another

    Hi,
    Can any one let me know the procedure if any for the following Scenario?
    I have my Oracle binaries let say in /u01 now i want to move it to /u02
    Thanx in advance..

    oracle binaries are residing in bin directory of ur oracle instance.
    say u have oracle instance running in /u01 and also the same oracle instance running in /u02, then u can move ur binaries to a different location. binaries are like pointers on the database which are used for routing the connection calls.
    this is to be done by shutting down all the servers properly.

  • How to display the results in order by based on search value

    Hi All,
    how to display the results in the below order.
    CREATE TABLE TEST( SONGID  NUMBER, TITLE   VARCHAR2(200))
    INSERT INTO TEST(SONGID,TITLE) VALUES (10,'AHMADZAI, MIRWAIS (CA)/ MADONNA (CA)');
    INSERT INTO TEST(SONGID,TITLE) VALUES (11,'CICCONE, MADONNA (CA)');
    INSERT INTO TEST(SONGID,TITLE) VALUES (12,'DALLIN, MADONNA LOUISE/STOCK');
    INSERT INTO TEST(SONGID,TITLE) VALUES (13,'MADONNA');
    INSERT INTO TEST(SONGID,TITLE) VALUES (14,'MADONNA (A)/ AHMADZAI, MIRWAIS (C)');
    INSERT INTO TEST(SONGID,TITLE) VALUES (15,'MADONNA (CA)');
    INSERT INTO TEST(SONGID,TITLE) VALUES (16,'MIRWAIS AHMADZAI, MADONNA');     
    INSERT INTO TEST(SONGID,TITLE) VALUES (17,'MIRWAIS (CA)/ MADONNA (CA),AHMADZAI');
    INSERT INTO TEST(SONGID,TITLE) VALUES (18,'MADONNA (CA),CICCONE');
    SELECT *FROM  TEST WHERE INSTR (TITLE, 'MADONNA') > 0
    output:
    SONGID     TITLE
    10     AHMADZAI, MIRWAIS (CA)/ MADONNA (CA)
    11     CICCONE, MADONNA (CA)
    12     DALLIN, MADONNA LOUISE/STOCK
    13     MADONNA
    14     MADONNA (A)/ AHMADZAI, MIRWAIS (C)
    15     MADONNA (CA)
    16     MIRWAIS AHMADZAI, MADONNA
    17     MIRWAIS (CA)/ MADONNA (CA),AHMADZAI
    18     MADONNA (CA),CICCONE
    Expected output :
    13     MADONNA
    14     MADONNA (A)/ AHMADZAI, MIRWAIS (C)
    15     MADONNA (CA)
    18     MADONNA (CA),CICCONE
    ...if user searches with 'MADONNA' , I have to display the results like title starts with 'MADONNA' first then rest of the records.
    Please let me know is it possible to display the results in that order.
    Regards,
    Rajasekhar

    This may be a bit more accurate:
    SQL> SELECT *
      2  FROM   TEST
      3  WHERE  INSTR (TITLE, 'MADONNA') > 0
      4  ORDER  BY INSTR (TITLE, 'MADONNA')
      5           ,TITLE
      6  ;
                  SONGID TITLE
                      13 MADONNA
                      14 MADONNA (A)/ AHMADZAI, MIRWAIS (C)
                      15 MADONNA (CA)
                      18 MADONNA (CA),CICCONE
                      12 DALLIN, MADONNA LOUISE/STOCK
                      11 CICCONE, MADONNA (CA)
                      17 MIRWAIS (CA)/ MADONNA (CA),AHMADZAI
                      16 MIRWAIS AHMADZAI, MADONNA
                      10 AHMADZAI, MIRWAIS (CA)/ MADONNA (CA)

  • How to join two lists and display the results in datasheet view.?

    hello,
    i have two lists that i would like to join, i know a method that has been described  in the link below
    http://www.codeproject.com/Articles/194252/How-to-Link-Two-Lists-and-Create-a-Combined-Ciew-i
    however, here the data view is only limited to 30 rows and my resultant list is huge. I would like to know if there is a possibility to view the resultant list in a data sheet view ?

    I don't believe you can use the OOTB Datasheet view when joining lists. However, you should be able to increase your limit from 30 items to as many as you need (that doesn't trip the threshold set in Central Admin).
    Dimitri Ayrapetov (MCSE: SharePoint)

  • How to get the result set in batches

    I have a query which results into large data. This data i want to display in a group of 20. After every 20 records i want to add header and footer to it.
    Is it possible to get the result set data into batch of 20 ? means can i specify start and end index of query ?
    regards
    Manisha

    What I am saying is that a big query with lots of
    joins will probably be slow, and as such would be a
    ripe candidate for batching the responses, if it were
    not possible to speed/optimize it. Batching is nice
    to look at for the user, but is not a solution for
    performance problems. In essence it is irrelevant
    that it adds a little performance deficit, as it
    appears to be running a lot quicker, and gives more
    feedback to the user.Then let me say it again....
    - "Join" is a term that applies to a method of doing queries in the database....
    - Query 1 which uses a join and returns 15 rows
    - Query 2 which does not use a join and returns 1500 rows.
    Given the above then Query 1 will provide better overall performance for the system than Query 2 in a properly configured database.
    If it doesn't then the database is not set up correctly.
    And again this will be irrespective of whether the query is scrollable or not.

Maybe you are looking for

  • Report to notify me if my RFC connection is succesfull??

    Hi guys, I want to create small report that will notify me every day (or every 12 hours) if my RFC connection is succesfull. Is it possible to send this notification on email or as message when user is loging on the system?? I have created RFC destin

  • Show Date Variable of report in drill down of report

    Hi I am using BI7.0 query designer and i am trying to build in the output of the date used in a variable as output in a drilldown in the report.This date is a keydate i use for making snapshots with APD's. Example: Keydate variable value: 01.07.2009

  • Order history, Order history

    How do you look at your order history for iphoto?

  • Internet has slowed dramatically

    Hi there, ive been havin problems with my net for around 3-4 days now, it was all fine and danday around wednesday / thursday time, butafter activating my skyHD the internet speed has dropped to 0.12mbps (checked by speedtest) Im not sure if the sky

  • Flush iTunes Library to remove old albums?

    Hi - does anyone know how I would get iTunes (either automatically or manually) to go through the albums in my browser window and remove the names of ones which don't exist anymore? I know that I could re-drag my entire collection into the main windo