Sum Counts

My query looks like below , every thing works fine . Only I need in Sep 2014 I need Total ( instead of 2 should be 81) .
Select 'Reports' AS ReportName,
datepart(month,Date) [mn],
datepart(year,Date) [yr],
datename(month,max(Date))+' '+convert(varchar(4),datepart(year,max(Date))) [Month],
Count(ReportName)[CountReports]
from DB.dbo.Table1
group by datepart(month,Date),datepart(year,Date)
ReportName      mn         yr            Month                   
CountReports
Reports          8        2014       August 2014                  
79
Reports          9        2014       September 2014             2
Any help will be appreciated
simam

That was an example which I have posted to illustrate how to get a running count within groups .
I've made some assumptions on your table schema, based on the query you have posted.
Here you go
drop table #temp
 create table #temp
 (ReportName varchar(30),
 [Date] datetime
insert into #temp values ('rep1','1-jan-2014')
insert into #temp values ('rep2','2-jan-2014')
insert into #temp values ('rep3','1-jan-2014')
insert into #temp values ('rep4','1-feb-2014')
insert into #temp values ('rep6','1-feb-2014')
insert into #temp values ('rep6','1-feb-2014')
insert into #temp values ('rep6','1-Mar-2014')
insert into #temp values ('rep6','1-April-2014')
insert into #temp values ('rep6','1-Dec-2014')
insert into #temp values ('rep6','1-Nov-2014')
 ;WITH g AS
   SELECT datepart(month,Date) [mn],
datepart(year,Date) [yr],
 count(reportname) as cnt
     FROM #temp
     GROUP BY datepart(year,Date) ,Datepart(month,[Date])
 SELECT 'Reports' name,mn,yr,
   countreports = SUM(cnt) OVER (ORDER BY yr,mn ROWS UNBOUNDED PRECEDING)
 FROM  g
 ORDER BY yr,mn
Hope this helps!!

Similar Messages

  • Get Column sum, count in sql developer

    Dear All seniors,
    I need help in oracle sql developer that after select statement when we got our result in below rows and coloums,
    then how to get its sum, count, etc.
    as in pl sql developer we simply right click at a column and then click on the desired function.
    is this facility also have in sql developer?

    We've kicked around the idea of doing this for awhile. I believe there's already an item in the Exchange if you want to up vote it. The challenge being if it's a result set which hasn't been fully fetched, doing an aggregate would require one - and that could be costly. Of course folks live in the grids so I see the value in this type of feature as well.
    As a workaround, you could of course export your data to CSV or XLS and do the calculations in your favorite spreadsheet software.

  • How to print SUM & COUNT at the end of the XML template

    Hello,
    I am generating a payment file in oracle Payments and at the end of the file, I would also like to add a trailer record with sum of the payments and number of payments. Can anyone have any suggestions on having a trailer record with SUM & COUNT.
    Thanks,

    You can use,
    COUNT and SUM of the column to get those values.
    In extext, add a new record and add these function on columns.

  • Getting Sum, Count and Distinct Count of a file

    Hi all this is a UNIX question.
    I have a large flat file with millions of records.
    col1|col2|col3
    1|a|b
    2|c|d
    3|e|f
    3|g|h
    footer****
    I am supposed to calculate the sum of col1 =9, count of col1 =4, and distinct count of col1 =c3
    I would like it if you avoid external commands like AWK. Also, can we do the same by creating a function?
    Please bear in mind that the file is huge
    Thanks in advance

    This sounds like homework for a shell class, but here goes. Save into a file, maybe "doit". Run it like this:
    $ ./doit < data
    <snip>
    #!/bin/sh
    got0=0
    got1=0
    got2=0
    got3=0
    got4=0
    got5=0
    got6=0
    got7=0
    got8=0
    got9=0
    sum=0
    cnt=0
    IFS='|'
    while read c1 c2 c3 junk; do
    # Sum and count
    echo "c1=${c1}"
    case "${c1}" in
    [0-9] )
         sum=$(expr ${sum} + ${c1})
         cnt=$(expr ${cnt} + 1)
    esac
    # Distinct
    case "${c1}" in
    0 )     got0=1;;
    1 )     got1=1;;
    2 )     got2=1;;
    3 )     got3=1;;
    4 )     got4=1;;
    5 )     got5=1;;
    6 )     got6=1;;
    7 )     got7=1;;
    8 )     got8=1;;
    9 )     got9=1;;
    esac
    done
    echo "cnt=${cnt}"
    echo "sum=${sum}"
    echo "distinct="$(expr $got0 + $got1 + $got2 + $got3 + $got4 + $got5 + $got6 + $got7 + $got8 + $got9)
    <snip>

  • Group queries (sum ,count, max,min)

    can anyone tell how to use the group queries ? i dont know  how to use exactly in abap. give the syntax and simple example with that group queries.

    hi go through following logic,
    it will solve ..
    program1:DATA:   AVERAGE TYPE P DECIMALS 2,
            SUM     TYPE P DECIMALS 2.
    SELECT AVG( LUGGWEIGHT ) SUM( LUGGWEIGHT )
    INTO   (AVERAGE, SUM)
    FROM   SBOOK.
    WRITE: / 'Average:', AVERAGE,
           / 'Sum    :', SUM.
    program2
    PARAMETERS: TBLNAME(50) DEFAULT 'SPFLI'.
    3 DATA: TOTAL_ROWS TYPE P.
    4 SELECT COUNT(*) FROM (TBLNAME) INTO TOTAL_ROWS. ç
    5 WRITE: / TBLNAME, TOTAL_ROWS.
    for MAX and Min
    SELECT MAX( MSGNR ) FROM T100 INTO C4A 
    WHERE SPRSL = 'D' AND                
           ARBGB = '00'.         
    SELECT MIN( MSGNR ) FROM T100 INTO C4A 
    WHERE SPRSL = 'D' AND                
           ARBGB = '00'.        
    if useful reward with points

  • Top 10 sum & count

    I have been working on this Select statement all day (blogs & testing) and I guess it's time to seek some help.
    This is for my golf league to determine who is in the lead and determine the points each person has earned. Each week the golfer plays we enter data into a table (ParPoints) about the round and the 3 columns pertinent for this query are GolfID,
    Season and Points. I suspect that I might come out of this with more than one Select statement and that is fine as I will be filling dataTables with the results before using it.
    First off I only want rounds from this season (2014). Then I want to order the Points DESC for each GolfID & select the top 10 (10 best rounds by points).   I only want 10 and 11-? aren't needed. I want to capture this raw data because I want
    to report on it. It would be a great help to get this step completed.
    Next using the raw data (above) I want to sum the points for each GolfID.
    Then I want to count all of rounds actually played by each golfer. Actually If this has to be done by itself I can do it, but making it part of the bigger query I can not do.
    So an help to get me started would be of great assistance.
    Thanks
    Gary

    Hello,
    If I understand correctly, you want to get the calculate the sum of  top 10 [points] for each [GolfID] group as well as count the [points]of the group. Please refer to the following statement
    --top 10 sum
    ;with cte as
    (select golfid, season, points, row_number() over (partition by golfid order by points desc ) as point_order
    from test )
    select golfid, sum (points) as total
    from cte
    where season='2014' and point_order<=3
    group by golfid
    --count
    select golfid, count(points) as count
    from test
    group by golfid
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • Sum count on multiple tables

    Hi Guys,
    Can't really figure out where to start whit this one.
    Table1: employees agenda, there has been a meeting where all the employees have spent 45 minutes each
    EMP_NR  
    TIME CNT_NR
    1792
      45     31385920
    1831
      45     31385920
    5469
      45     31385920
    2159
      45     31385920
    2272
      45     31385920
    7827
      45     31385920
    7652
      45     31385920
    2455
      45     31385920
    4353
      45     31385920
    Table2: the clients that have been discussed in that meeting
    CL_NR 
    CNT_NR
    22546
    31385920
    24575
    31385920
    27789
    31385920
    Objective: 
    Find all the records per CNT_NR (9 in the example of TABLE1) in TABLE1 and sum the total time (9*45=405). The total
    time has to be divided over the number of records found in TABLE2 with the same CNT_NR. So in this case it would be 405 minutes divided by 3 clients = 135 minutes per client. The total time per client (135 min) can be displayed in a separate colomn.Please
    don't use this specific CNT_NR, this varies.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    Your picture is a mess. TIME is a data type in SQL, so it can not be a column name. We can have longer data element names in 2015; you are still stuck back in FORTRAN I where we were limited to six characters. What the heck is a “CNT”? Every guess I make is
    obscene. Rows are not records; that is more 1960's FORTRAN! 
    Here is a guess at repairing this:
    CREATE TABLE Agenda
    (emp_id CHAR(4) NOT NULL PRIMARY KEY 
     REFERENCES Personnel(emp_id), 
     meeting_duration INTEGER NOT NULL
     CHECK (meeting_duration > 0), 
     meeting_nbr CHAR(8) NOT NULL); 
    INSERT INTO Agenda
    VALUES
    ('1792', 45, '31385920'), 
    ('1831', 45, '31385920'), 
    ('2159', 45, '31385920'), 
    ('2272', 45, '31385920'), 
    ('2455', 45, '31385920'), 
    ('4353', 45, '31385920'),
    ('5469', 45, '31385920'), 
    ('7652', 45, '31385920'), 
    ('7827', 45, '31385920');
    CREATE TABLE Clients
    (client_id CHAR(5) NOT NULL PRIMARY KEY, 
     meeting_nbr CHAR(8) NOT NULL);
    INSERT INTO Clients
    VALUES
    ('22546', '31385920'),
    ('24575', '31385920'),
    ('27789', '31385920');
    >> Find all the records [sic] per client_nbr (9 in the example of Agenda) in Agenda and sum the total time (9*45=405). The total time has to be divided over the number of records [sic] found in Clients with the same client_nbr. So in this case it would
    be 405 minutes divided by 3 clients = 135 minutes per client. The total time per client (135 min) can be displayed in a separate column. Please don't use this specific client_nbr, this varies. <<
    WITH Meeting_Duration (meeting_nbr, meeting_duration_tot)
    AS
    (SELECT meeting_nbr, SUM(meeting_duration)
       FROM Agenda
      GROUP BY  meeting_nbr),
    Client_per_Meeting (meeting_nbr, client_cnt)
    AS
    (SELECT meeting_nbr, COUNT(client_id) AS client_cnt
       FROM Clients)
    SELECT meeting_nbr, 
          (meeting_duration_tot/client_cnt) AS client_duration
      FROM Meeting_Duration AS D,
           Client_per_Meeting AS C 
     WHERE C.meeting_nbr = D.meeting_nbr;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • I'm being stupid, again. Sum & Count, together

    Hi-
    I thought that this should be easy and I was able to do this...nope.
    i need to sum a value for each distinct count.  Having read a few post, i think i need an over() function.
    select distinct
        [Training Title],
        [Training Type],
        count(CASE WHEN [user id] IS NULL THEN 0 ELSE 1 END) as 'Number',
        sum(cast([training hours] as float)) as 'Total Hours',
        count([training object id]) as 'Offerings'
    -- this is duping, think i need an count([training object id]) over(PARTITION BY [TRAINING TITLE] )
    from q2_2014
    where [training type] = 'session'
    group by
        [Training Title],
        [Training Type]

    data:
    Training Title
    user id
    training hours
    training object id
    crs1
    a1
    0.25
    id-1
    crs1
    b1
    0.25
    id-1
    crs1
    c1
    0.25
    id-2
    crs1
    d1
    0.25
    id-2
    csr2
    a1
    0.25
    id-1a
    crs2
    b1
    0.25
    id-1b
    crs3
    a1
    0.25
    id-1
    results:
    Training Tile
    Count Users
    Total Hours
    Number of Offerings
    crs1
    4
    1
    2
    crs2
    2
    0.5
    2
    crs3
    1
    0.25
    1

  • Sum/Count Question

    Hi: I'm very new to Crystal Reports, and have a question that is probably pretty simple, but has me stumped and at a standstill...
    I've built a report in Excel that determines the number of days between two date columns, then has a series of summary fields that count how many records have 1 day, how many have 2 days, ... 3 days, etc... I'm trying to build something similar in CR that will do the same thing, but I can't find it. I'm thinking it should have something to do with the Count (fld, condfld) function, but think I'm having trouble getting the syntax right. Any help here?
    Thanks!
    Edited by: dthornton on Jan 15, 2010 11:48 AM

    I'm now looking for a way to show that result as a percentage of all records returned
    Sure.  Lets assume you have a formula @DaysDiff which is calculating the days difference between two days.  Not let's say you have a running total RT_OneDaysDiff which is counting your records  but only when @DaysDiff = 1.  If you want to know the percentage of records where Days Diff = 1 compared to the total number of records, you would create a formula as followis:
    if @count(rowidentifier) <> 0
         then @RT_OneDaysDiff / count(rowidentifier)
    Fuskie
    Who would then repeat for each desired number of days difference...

  • TSQL query to calculate Count / Sum grouping by date on a Pivot Table

    Hi All
    I need help to group the pivot table output to group by dates and sum/count the values. I have a table like shown below.
    Date
    Student 
    Subject
    Hunt
    Marks
    18/02/2014
    Sam 
    Maths
    1
    20
    18/02/2014
    Sam 
    Maths
    1
    10
    18/02/2014
    Sam 
    Maths
    2
    30
    18/02/2014
    Luke
    Science
    1
    50
    17/02/2014
    Sam 
    Maths
    2
    50
    17/02/2014
    Luke
    Science
    2
    60
    16/02/2014
    Luke
    Science
    2
    20
    16/02/2014
    Luke
    Science
    3
    20
    I want to Group by dates and move the Hunt to columns calculating their counts and sum their marks too. Like given below.
    I wrote a pivot query like below but If i group it with dates and calculate the total marks it throws aggregate errors.
    Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
    Go
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
    Go
    select * from Student_Log
    select [DATE] , [Student], [Subject] ,[1],[2],[3],[4],Total =([1]+[2]+[3]+[4])
    from
    ( select [Date], [Student], [Subject],[Hunt],[Marks] from Student_Log
    )x
    pivot
    count ( [Hunt]) for [Hunt]
    in ([1],[2],[3],[4])
    )p
    order by [Date] desc
    I have done this far only. More than this I need to enhance it with the Percentage of Hunts for each Student.
    ie like below table.
    On 18th Sam in Maths he had 2 rows on 1st hunt  and 1 row on 2nd hunt. So On the Pivot table is it possible to represent it on percentage using the Total Attempts column.
    Thanks a lot in advance.
    Its runnung in SQL 2000 Server.

    Create Table Student_Log ([Date] datetime ,Student varchar (20), Subject varchar (20) ,Hunt int ,Marks int )
    Go
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','1','10')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Sam ','Maths','2','30')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-18 15:00:00.000','Luke','Science','1','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Sam ','Maths','2','50')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-17 15:00:00.000','Luke','Science','2','60')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','2','20')
    INSERT INTO Student_Log ([Date],Student, [Subject],Hunt,Marks) VALUES('2014-02-16 15:00:00.000','Luke','Science','3','20')
    Go
    select * from Student_Log
    ;with mycte as
    Select [Date], [Student], [Subject] ,
    Count(CASE WHEN [Hunt]=1 Then Hunt End) as Hunt1,
    Count(CASE WHEN [Hunt]=2 Then Hunt End) as Hunt2,
    Count(CASE WHEN [Hunt]=3 Then Hunt End) as Hunt3,
    Count(CASE WHEN [Hunt]=4 Then Hunt End) as Hunt4,
    Count(CASE WHEN [Hunt]=1 Then Hunt End)
    +Count(CASE WHEN [Hunt]=2 Then Hunt End)
    +Count(CASE WHEN [Hunt]=3 Then Hunt End)+
    +Count(CASE WHEN [Hunt]=4 Then Hunt End) as Total,
    ISNULL(SUM(CASE WHEN [Hunt]=1 Then Marks End),0) as Mark1,
    ISNULL(SUM(CASE WHEN [Hunt]=2 Then Marks End),0) as Mark2,
    ISNULL(SUM(CASE WHEN [Hunt]=3 Then Marks End),0) as Mark3,
    ISNULL(SUM(CASE WHEN [Hunt]=4 Then Marks End),0) as Mark4
    from Student_Log
    Group By [Date], [Student], [Subject]
    Select [Date], [Student], [Subject]
    , Cast(Hunt1*1./Total*100 as int) as [1]
    , Cast(Hunt2*1./Total*100 as int) as [2]
    ,Cast(Hunt3*1./Total*100 as int) as [3]
    ,Cast(Hunt4*1./Total*100 as int) as [4]
    ,Total,Marks=( Mark1+Mark2+Mark3+Mark4)
    from mycte
    order by [Date] DESC, Student desc
    drop table Student_Log

  • Error when trying to use SUM with COUNT

    I have the following query which works fine. However, I need to add another column that is the SUM of the firs column ("OPEN"). I have also included that query but I cannot get it to work. Any help would be appreciated.
    SELECT
    TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    ) as OPEN,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
    ) as TOTAL
    FROM RAW_APP_DATA R, APP_STATE A
    WHERE R.RAD_STATUS = A.STATE_ID
    AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
    GROUP BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
    ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
    (RESULTS)
    THISDAT OPEN TOTAL
    2002-08 1 37
    2002-09 0 40
    2002-10 0 33
    2002-11 1 25
    2002-12 2 22
    2003-01 3 25
    2003-02 4 101
    2003-03 5 99
    2003-04 5 85
    2003-05 3 69
    2003-06 17 90
    2003-07 6 57
    2003-08 26 89
    2003-09 43 117
    2003-10 59 110
    2003-11 47 67
    2003-12 75 80
    2004-01 9 9
    18 rows selected.
    SECOND QUERY (DOES NOT WORK)
    SELECT
    TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    ) as OPEN,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
    ) as TOTAL,
    SUM(
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    )) as "OPEN TOTAL"
    FROM RAW_APP_DATA R, APP_STATE A
    WHERE R.RAD_STATUS = A.STATE_ID
    AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
    GROUP BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
    ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
    DESIRED RESULT SET
    THISDAT OPEN TOTAL TOTAL OPEN
    2002-08 1 37 1
    2002-09 0 40 1
    2002-10 0 33 1
    2002-11 1 25 2
    2002-12 2 22 4
    2003-01 3 25 7
    2003-02 4 101 11
    2003-03 5 99 16
    2003-04 5 85 21

    You are right those are group functions not aggregate. However, if I try to group by with the group functions I get an error (see code).
    SELECT
    TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    ) as OPEN,
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
    ) as TOTAL,
    SUM(
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    )) as "OPEN TOTAL"
    FROM RAW_APP_DATA R, APP_STATE A
    WHERE R.RAD_STATUS = A.STATE_ID
    AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
    GROUP BY
    TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm'),
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
    COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
    COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
    ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
    ORA-00934: group function is not allowed here
    Do I group by the columns individually?

  • Count and Sum running total

    Can i sum and couunt running total in formula?.
    Please let me know.

    Hey, we can do count and sum functions in Running total.
    These functions are available in crystal reports for  summary fields.
    We can create  the running total based on the type of summary like Sum, count, max, min, distinct count, etc.
    We can do Evaluation for each record or on group or on each field  and also be done by writing a formula.
    We can  do count or sum by manual running total by writing a formula in the formula workshop.
    Based on our requirement we can use both functionalities.
    Please let me know  if you have any queries.
    Regards,
    Naveen.

  • How can I select count/sum/avg by sliding window ???

    Hi, Can you help me somebody?
    For example I have table with DateTime field. And now, I want to find which 1 hour interval contains maximum of records. Resolution is 1 minute. This mean that there is 1380 intervals in one day (00:00-01:00, 00:01-01:01, ... ... 22:59-23:59,23:00-00:00)
    There is problem using analytic functions with window clausule because in table there is not record for every minute.
    How can I do it?
    PS: Sorry my poor english

    Still not very clear, but this time my guess is you mean this:
    SQL> create table mytable
      2  as
      3   select date '2007-07-18' + round(dbms_random.value(0,1440))/1440 mydate
      4     from dual
      5  connect by level <= 2000
      6  /
    Tabel is aangemaakt.
    SQL> with all_minutes as
      2  ( select date '2007-07-18' + (level-1)/1440 mytime
      3      from dual
      4   connect by level <= 1440
      5  )
      6  select a.mytime
      7       , sum(count(t.mydate)) over (order by mytime range between current row and interval '1' hour following) number_of_records
      8    from all_minutes a
      9       , mytable t
    10   where a.mytime = t.mydate(+)
    11   group by a.mytime
    12  /
    MYTIME                                   NUMBER_OF_RECORDS
    18-07-2007 00:00:00                                     93
    18-07-2007 00:01:00                                     94
    18-07-2007 00:02:00                                     92
    18-07-2007 00:03:00                                     91
    18-07-2007 00:04:00                                     92
    18-07-2007 00:05:00                                     90
    18-07-2007 00:06:00                                     89
    18-07-2007 23:32:00                                     36
    18-07-2007 23:33:00                                     32
    18-07-2007 23:34:00                                     32
    18-07-2007 23:35:00                                     32
    18-07-2007 23:36:00                                     32
    18-07-2007 23:37:00                                     30
    18-07-2007 23:38:00                                     29
    18-07-2007 23:39:00                                     29
    18-07-2007 23:40:00                                     25
    18-07-2007 23:41:00                                     25
    18-07-2007 23:42:00                                     23
    18-07-2007 23:43:00                                     22
    18-07-2007 23:44:00                                     20
    18-07-2007 23:45:00                                     20
    18-07-2007 23:46:00                                     19
    18-07-2007 23:47:00                                     18
    18-07-2007 23:48:00                                     18
    18-07-2007 23:49:00                                     17
    18-07-2007 23:50:00                                     15
    18-07-2007 23:51:00                                     15
    18-07-2007 23:52:00                                     14
    18-07-2007 23:53:00                                     14
    18-07-2007 23:54:00                                     14
    18-07-2007 23:55:00                                     10
    18-07-2007 23:56:00                                      7
    18-07-2007 23:57:00                                      5
    18-07-2007 23:58:00                                      3
    18-07-2007 23:59:00                                      1
    1440 rijen zijn geselecteerd.Regards,
    Rob.

  • Grand Total SUM of COUNT

    Hi all!
    I am trying to grab a total of the COUNTS and SUM them together. I am trying to build a chart with graphics builder, but alas, that software has a 2000 character limit for its queries, so the inline view approach did not work. Here is my query:
    SELECT
    to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY') Base_Entry_Year,
    count(*)
    -- SUM(count(*)) does not work
    FROM
    per_all_assignments_f paaf,
    per_all_people_f papf,
    per_jobs pj,
    per_job_definitions pjd
    WHERE
    papf.person_id = paaf.person_id
    AND paaf.ass_attribute14 IS NOT NULL
    AND to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY') IS NOT NULL
    AND (papf.employee_number IS NOT NULL OR papf.person_type_id = 3)
    AND paaf.job_id = pj.job_id
    AND pj.job_definition_id = pjd.job_definition_id
    AND pjd.segment1 NOT IN ('09140018', '09340006', '09140037', '09140051', '09140052', '09140054', '09140055')
    GROUP BY
    to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY')
    ORDER BY
    to_char(to_date(papf.attribute1, 'YYYYMMDD'), 'YYYY')
    Any ideas on how I can accomplish this? Thanks!
    Steve

    Hi,
    I ran two different queries:
    1.
    select KeyCol, count(*), Sum(count(*)) over ()
      from Test t
    group by t.KeyCol ;
    Result:
            KEYCOL     COUNT     SUM(COUNT(*))OVER()
    1     DHP     398     5505
    2     FIH     1     5505
    3     FIN     2971     5505
    4     FLP     5     5505
    5     HTBC     1     5505
    6     Z99     22     5505
    7          2107     55052.
    select KeyCol, count(*), count(*) over ()
      from test t
    group by KeyCol;
    Result:
            KEYCOL     COUNT     COUNT(*)OVER()
    1     DHP     398     7
    2     FIH     1     7
    3     FIN     2971     7
    4     FLP     5     7
    5     HTBC     1     7
    6     Z99     22     7
    7          2107     7This shows that both queries are not equivalent.
    Thanks,
    Dharmesh Patel

  • SUM and count next to each other

    SUM and count next to each other
    I would like to have the measurements SUM and COUNT cells being next to each other.
    As a default it shows up like this:
    .......SUM............. COUNT
    ......RegionA RegionB RegionA RegionB
    2000..... $..... $..... nn..... nn
    2001..... $..... $..... nn..... nn
    2002..... $..... $..... nn..... nn
    Can I change this somehow to:
    ......RegionA.....RegionB
    ......SUM COUNT ...SUM COUNT
    2000...$....nn......$... nn
    2001...$....nn......$... nn
    2002...$....nn......$... nn
    thnx
    Endre

    Select your axis "Region" and move it over (i.e. on top of) your data points (SUM, COUNT, etc.).

Maybe you are looking for

  • IPod not recognized by computer or iTunes

    So, this seems to be a common problem. When I connect my iPod to my computer, the computer nor iTunes recognize the laptop. I've tried connectivity tests and it can't detect the iPod. However, the USB port does recognize other devices. I've tried the

  • Java stops working under OS 10.9. How to fix?

    Since upgrade to Mac OS 10.9 java does not work any more in Firefox, but does work in Safari. http://www.java.com/en/download/installed.jsp yields "unable to verify if Java is currently installed" Steps taken: * re-install newest Java version 7.45 (d

  • Creating custom interface panels in LabVIEW for use in VBAI.

    Greetings everyone, I hope that someone can give me some insight with the following problem. I have on my bench a 1742 Smart Camera and a computer loaded with VBAI 3.6 and LabVIEW 8.6 Pro (all the latest and greatest stuff). Up to this point, everyth

  • Problem with Dell 2208WFP

    This is doing my head in.Just got the above monitor which is replacing my old VGA Viewsonic but it just keeps on going to powersave mode.However if I disconnect the VGA cable from the Viewsonic and put it in the Dell it works!.I've tried VGA and DVI

  • Problem in oracle 10g(client) to server is oracle 8i

    i want to coneect oracle 10g is client to oracle 8i is server. so i am getting problem. how to connect oracle 10g (client) to oracle 8i server.please give me steps.