Acounting the total of tables group by year

Hi there, I need help
I am writing simple query that gives the result on total counts by group and sort by year.
When I do single query it works
select to_char(date, 'yyyy') as year, count(*) as total from table_name group by to_char(date, 'yyyy') order by to_char(date, 'yyyy');
I need to use above query using through dba_tables. I have two thousand owners which has same tables.
thanks,

all,
so far
This is what I have
set serveroutput on
declare
cursor c1 is select owner, from all_tables where table_name ='MESSAGE' order by owner;
sql_stmt varchar2(4000);
cnt_val number;
cnt_year date;
begin
for c1_rec in c1 loop
sql_stmt:= 'select count(*), to_char(date, "yyyy") from '||c1_rec.owner||' .MESSAGE';
execute immediate sql_stmt into cnt_val, cnt_year;
dbms_output.put_line (rpad(c1_rec.owner,20) ||' ' ||cnt_val|| ' '||cnt_year);
end loop;
end;
when I run the above query, the errors at line 1
ora-00904: "yyyy": invalid identifier
ora-06512: at line 12
any idea, please help me....

Similar Messages

  • How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column

    Please Help!!!
    How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
                                      January 2014         January
    2013                            +/-
                    Region   Entry   Exit  Total    Entry   Exit   Total   (Total of Jan2014-Total of Jan2013)
                    A               2         3      
    40        5       7        30                    40-30= 10

    What is a table structure? Sorry cannot test it right now..
    SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
    FROM tbl
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to show the total in group footer in group header?

    Hello,
    I am having difficulties while showing the total of a group footer in the group header. The total in the group footer is correct, but when i am placing the formula in the header it is giving me 0.
    I am having 2 formulas to get the total which i placed in the footer:
    1.
    whileprintingrecords;
    numbervar sumpctx := sumpctx + {@Sum OB};
    2.
    whileprintingrecords;
    global numbervar sumpctx;
    numbervar DispSales;
    DispSales := sumpctx;
    sumpctx := 0;
    DispSales;
    now, I want to add the 2 formula in the header, but it is giving me 0 value, But in the group footer it is showing the correct value.
    I tried to do:
    Sum ({@Sum OB}) and it is giving that the field can not be summarized.
    The group Name is @Entity which is grouped by.
    @Entity :
    if {Customer.NAME}="NONE" THEN
    " OB"
    ELSE {Customer.NAME}
    Thanks in advance for yopur help.
    Regards

    Hi,
    What i was trying to say there is a hierarchy in report design and records are processed in that way.
    Report header/footer - only once
    Page header/footer -once in a page
    detail -n no of times ,n-no of rows of data
    First report header will be processed,then page header n detail,after that report and page footer.
    If u insert a group,then the order will be-
    report header,page header,group header,detail,group footer,detail,report and page footer.
    When u r in group header,all the records are not processed,that results the sum as zero.
    But when u create a formula,it calculates the sum first and then u put it there.
    I hope this time it will be helpful for u.
    Regards,
    Misra P.

  • Sum Based on The Value of Another Group

    I'm using RS 2005 and trying to accomplish the following:
    Here is the detail data for those customers with negative balance. For example cust2 = -50 and cust3 = -30
    Cust ID    Ord #   Balance
    cust1        1          30
    cust1        2          80
    cust2        1        100
    cust2        2       -150
    cust3        1        100
    cust3        2         70
    cust3        3       -200
    cust4        1       100
    cust4        2         50
    cust5        1       250
    cust5        2         20
    Total (net) balance for cust1 is 110
    Total (net) balance for cust2 is -50 (100 + -150)
    Total (net) balance for cust3 is -30 (100 + 70 + -200)
    Total (net) balance for cust4 is 150
    Total (net) balance for cust5 is 270
    i have to aggregate the customer balance in group A (group by Cust ID)
    For group B, Division - I only want sum the  balance of the customers within that division that have a negative balance (the balance aggregate in group A).
    so the Total for Division (group B) is  -80 (bal of cust2 + bal of cust3)
    in summary, i have to aggregate the balance for each customer, base on the balance of each customer (neg bal only), i aggregate the balance for the Division.  Your help/suggestion is greatly appreciated.

    Hi Bryan,
    First, did you trying to do this at query level or at RS using grouping and expression?
    With query, to get aggregate for each customer, simply do:
    select distinct Cust_ID, TotalBalance = sum(Balance)
    from <your table>
    group by Cust_ID
    To get the aggregate for division, try:
    select Total = sum(case when TotalBalance > 0 then 0 else TotalBalance end)
    from (
    select distinct Cust_ID, TotalBalance = sum(Balance)
    from <your table>
    group by Cust_ID
    ) t1
    ** Didn't see this has been replied.

  • Problem in finding the total count

    my table as below:
    ID code group cand
    A 001 01 1
    A 001 02 1
    A 001 02 2
    A 002 01 1
    A 003 01 1
    B 001 01 1
    B 001 01 2
    B 001 02 1
    B 002 01 1
    C 002 01 1
    C 002 01 2
    C 003 01 1
    Here is what I want
    ID Code tot_grp num_cand
    A 001 4 3
    A 002 4 1
    A 003 4 1
    B 001 3 3
    B 002 3 1
    C 002 2 2
    C 003 2 1
    where tot_grp is the total number of groups for each ID
    and num_cand is the total number of candidates for each ID with that specific
    code
    Can I do it in one sql statement ?
    Thank you

    you said
    where tot_grp is the total number of groups for each ID
    and num_cand is the total number of candidates for each ID with that specific
    code
    Can u be more specific what should be present in tot_grp column.
    Is it contains
    a)sum of group for a given ID & code combination.
    If yes then sql would be
    select id,code,sum(group) tot_grp,count(cand) num_cand
    from <table_name>
    group by id,code
    having the output ID Code tot_grp num_cand
    A 001 5 3
    A 002 1 1
    A 003 1 1
    B 001 4 3
    B 002 1 1
    C 002 2 2
    C 003 1 1
    2) Total No of groups(only the count) for a given Id & code
    If yes then sql would be
    select id,code,count(group) tot_grp,count(cand) num_cand
    from <table_name>
    group by id,code
    having the output ID Code tot_grp num_cand
    A 001 3 3
    A 002 1 1
    A 003 1 1
    B 001 3 3
    B 002 1 1
    C 002 2 2
    C 003 1 1
    If none of the above condition is correct can u please be more clear .

  • Sort on group total ( Sum  of group)

    I need to sort output either on the details and when the details are suppressed on the total of a group
    If I suppress details and manually change sorting using
    the designer and "Group Sort Expert", " For this group sort All based on Sum of table.column" gives me exactly what I need.
    However, I need to switch this "Sort on Total" on and off programatically.
    Tried to change or add a TopBottomNSortField programtically using RAS - with no success yet.
    Am I using the correct approach at all ?
    Using CR 2008 ( 12.3.0.601 ) on Windows, fat client
    Thanks
    Oskar
    Edited by: Oskar Atkinson on Apr 15, 2011 1:05 AM

    I wonder if you should be looking at the Group itself (GroupNameFieldClass.Group property in the documentation).  It has a SpecifiedGroupOptions property that you can specify the sorting criteria.  Maybe try setting this in the designer and see if you can retrieve the sorting through your application and then try to change it if you can.

  • Cross tab report's -one column display total counts of previous financial year, one column current financial year

    Hi
    I'm using CR XI. I'm attempting to create  a cross-tab report where:
               Added       Total
    AF         12            23
    F            15           30
    CO         18           50
    Where AF etc is the categoty of items, Added is the total count of previous finanical year(e.g. 1 July 2006 to 30 June 2007), Total is the total account of current finanical year.
    The count is based on created_date field(e.g. ITD.DTE -- ITD is the table, DTE is the field).
    Although I can at the moment only display the value correctly in "Added"  column, if I tried to display the Total column, the two columns always have the same value.
    How could I achieve the above desired results by using fomula? I would appreciate it very much if anyone could help me with this?
    Thanks in advance
    JS

    Create 2 formulas, 1 for the previous year and 1 for current, similar to the following;
    1) if date({Orders.Order Date}) in date(2003,07,01) to date(2004,06,30) then 1 else 0
    2) if date({Orders.Order Date}) in date(2004,07,01) to date(2005,06,30) then 1 else 0
    Add both of these formulas as the summarized fields in the crosstab

  • How do i find the total number of fields within all tables in one of my databases

    I'm in the process of creating some "gee whiz" metrics for one of my applications and want to find the total number of columns contained in its database.  Is there a stored procedure to get this information that would save me the effort
    of opening each of my 66 tables and counting the columns?  I also have the same question for my 138 views.  Thank you for any ideas you care to offer...............Phil Hoop
    Phil Hoop

    Hi Phil,
    Assumes SQL 2005 or higher
    Let 's try simple one ....
    SELECT COUNT(col.column_name), col.table_name
    FROM information_schema.columns col
    JOIN information_schema.tables tbl
    ON tbl.table_name = col.table_name
    AND tbl.table_schema = col.table_schema
    AND tbl.table_catalog = col.table_catalog
    AND tbl.table_type = 'VIEW'
    GROUP BY col.table_name
    Let me know if this will help you.
    If you think my suggestion is useful, please rate it as helpful.
    If it has helped you to resolve the problem, please Mark it as Answer.
    Varinder Sandhu www.varindersandhu.in

  • Monthly and Yearly info on the same Pivot Table

    Hi everyone,
    I have a couple of questions.
    1) I want to show the same results by month and by year on the same pivot table. Is there any way this can be done?
    2) I would also like to show data on graphs by month. To do this i have added my date field to the table (hidden) and used the function MONTHNAME(expr). This works fine except that any transactions in April 2007 get grouped with any transactions in April 2008, and the same with the rest of the months. Is there any MONTHYEAR function or the like, that differentiates between months from different years?
    Any help would be great!
    Thanks

    1) I believe you need 2 pivot tables
    2) Can you give me more details on which object and which date you are using? I think it should be possible to get the required output.

  • Formula to provide a varaible the total value for a group

    Hi,
    I need to create a formula which outputs the value for a single group. For example, two groups are:
    Group: Year
         Group: Products
    I only need to place in the footer the total for year 2012, product jam. The report contains dteails for many products and years.
    Any one help me with this formula?
    Cheers,

    Hi Leo,
    Create this formula and place it on the Group Header 2. You may suppress this formula as we don't really need to display it.
    WhilePrintingRecords;
    numbervar summ;
    if {Year} = 2012 and {Product} = "Jam" then
        summ := Sum ({Product}, {Year}))
    Note. If the {Year} field is a date field, then you need to use a function to extract the year like:
    Year({Year_field}) = 2012
    Create another formula to display the sum and Place it on the Report Footer:
    WhilePrintingRecords;
    numbervar summ;
    Hope this helps!
    -Abhilash

  • Format the total value in the column of the graph table

    Hello all,
    I have a graph table and I need to format the total value in the column of the table.
    I am trying to find my table bean with the code below but it's not working in the processRequest. Is there anything else that should be done?
    // Get the graph
    OAGraphTableBean graphBean = (OAGraphTableBean)webBean.findChildRecursive("MyGraph");
    // Get the table
    OATableBean tblBean = (OATableBean)graphBean.findChildRecursive("MyTable");
    The tblBean is null in the processRequest. In the processFormRequest the tblBean is not null.
    Thanks and Regards,
    Andrea

    Hi,
    The code OAGraphTableBean graphBean = (OAGraphTableBean)webBean.findChildRecursive("MyTable"); does not work because in this case I am getting the table but casting to a graph.
    The MyTable bean is a child of MyGraph.
    When creating a graph bean we have the option to create a table as a child (select your graphTable region in the Structure pane, and choose New > tabularFormat - to create the table).
    The table bean child I can get just in the processFormRequest, but the graph I can get in both processRequest and processFormRequest.
    I need to get the table bean in the processRequest to format the total value column.
    Do you know if is there anything else that should be done to format the total column?
    Thanks and Regards,
    Andrea

  • How to do the ALV report output in groups and caluculate the tOTALS(URGENT

    Hi
    In my ALV report output .I have to group the output based on the DAYS field
    0-10 days in one group
    10-30 days in one group
    above 30 days one group
    There is also a field by name "AMOUNT" in my output.
    I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.
    Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report
    Thanks in Advance

    Please don't repost your questions...
    Check out my answer in your other post.
    How to make the ALV report in groups  and caluculate the TOTALS
    Regards,
    Naimesh Patel

  • How to calculate the total of absences? How to collect data from a specific line of a table?

    Hi,
    Again, I made a nice coloured picture from a screen capture which summarise the improvements that I would like to make in my form,
    Situation:
    For an educational purpose, I made this form   to simplify the way of recording the data and also to develope the independence of the students.
    ( I am doing this on a voluntary basis, working extra hours on my free time but I don't really mind because I am learning a lot of things in the same time)
    After being tested by the teacher, the student has to record the short date, the lines memorised, his grade, number of mistakes, and his attendance.
    I created everything in Word, then converted the file in PDF, then I created all the different fields with Adobe acrobat.
    There is in total 4 sheets, there are all similar except the first one in which there is a box with: date started, date finished, total time spent, absences.
    Below this box there is a table with 16 lines from (A to P) and 7 columns (Days, Date, From.. to.. , Grade, No. lines memorised, No. Errors, Attendance) ( so this table is present on all the sheets)
    Due to the fact that some students need more time than others, and also beacause some text need more time, I estimated a need of 4 sheets at the very most.
    I would like to make the following amelioration and automate the inputting of some of the data because I know that some of the students will certainly forget, so to avoid this scenario I am trying to make this form the easiest possible.
    screen capture of the form:
    screen capture of the form editing, you can see the names of the different fields:
    here is the form (only the first page) : http://cjoint.com/12fe/BBotMMgfYIy_memorisation_sheet_sample.pdf
    In  yellow 00000:
    At present, the students has to input the total of absences manually, is there a way ( script) to automate this by initialising the field next to "Absences" at  " 0 day"   and then everytime that Absent is selected from the COMBO BOX, it add 1 and it is displayed like this:  " 1 day" then " 2 days"  then " 3 days" etc … (so from what I read I have to initialise a counter a the beginning and then for (i...   ) count= count++; something like this...
    Furthermore, I need a solution to overcome the possibility that a second sheet may be needed for the same student; therefore I would need the data from the "attendance column" from the second sheet ( and perhaps the 3rd and 4th aswell) to be added on the "absences field" in the first sheet
    My idea: everytime that the short date is inputted in the first line (next to A) in the "Date" column of one of the 4 sheets then we check the 16 Combo box of the attendance column in this sheet instead to check 16*4=64 fields fot the 4 sheets in one go?
    but I don't know at all how to write it in Javascript. Or perhaps there is a way more easier than that?
    Shall I allocate a value for Absent on the “ export value”?
    In purple
    At present I wrote a simple script which matches the number of lines to the poem selected (Eg.  if I select the poem V.Hugo,  the number "36" will appear next to Number of lines).
    Again I would like the make the life of the students very easy so I would like a script which detects this number “36” on the "From .. to …" column,  as soon it is detected (on the first sheet or 2nd or 3rd or 4th)  check from the same line if "A / Pass" or "B / Pass" have been selected in the "Grade" column ,if yes the short date inputted on this line will be written on the field next to "Date finished" .
    this is a simple example with 36 lines only but somethimes, the students may have to memorise 80 lines and more, this is the reason for having 4 sheets in total.
    So basically I would like to automate the field next to" Date finished:" with a script that collect the short date from the day in which the student has finished his memorisation with "A / Pass" or "B / Pass"
    As for the "Total time spent" George Johnson helped me with a script that calculate the difference betwen date started and date finished (thank you)
    I am sollicting your help, because after trying for hours I was really confused with the different if/else needed. And in top of that, it’s my first experience with Javascript.
    I anticipate your assistance, thanking you in advance.

    I found this for counting the absences, its give you the total that's perfect, but is there a better methode which avoid me to write all the fields name, more simple????
    ( I found the idea here : Re: Total number added automatically  )
    // custom calculation script for field "Total #"
    function CountFields(aFields) {
    var nFields = 0;
    for(i = 0; i < aFields.length; i++) {
    try {
    // count null values, export value of Absence is 0;
    if(this.getField(aFields[i]).value == "0") nFields++;
    } catch(e) {
    if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);
    else app.alert(e.toString());
    } // end catch
    } // end for aFields
    return nFields;
    // create array of field names to count
    var aNames = new Array("Sheet1AttendanceA","Sheet1AttendanceB","Sheet1AttendanceC","Sheet1AttendanceD","Sh eet1AttendanceE","Sheet1AttendanceF",
    "Sheet1AttendanceG","Sheet1AttendanceH","Sheet1AttendanceI","Sheet1AttendanceJ","Sheet1Att endanceK","Sheet1AttendanceL",
    "Sheet1AttendanceM","Sheet1AttendanceN","Sheet1AttendanceO","Sheet1AttendanceP" );
    // count the non-null fields;
    event.value = CountFields(aNames);
    As for the 2nd question, I've tried to do something similar to the previous script, but of course it doesn't work, but I am quite sure that the idea is similar:
    I don't know also how to add the other condition: the student should get A / Pass or B / Pass in order to consider he has finished??? and also how to check these condition from page 2, 3 and 4 and collect the date
    function Datefinished(bFields) {
    d2.value = nFields[i].value;
    for(i = 0; i < aFields.length; i++) {
    try {
    if(this.getField(aFields[i]).value == this.getField("NumberLines").value) d2.value = nFields[i].value;
    } catch(e) {
    if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);
    else app.alert(e.toString());
    } // end catch
    } // end for aFields
    return nFields;
    // create array of field names to check
    var aNames = new Array("Texte00","Texte54","Texte56","Texte58","Texte60","Texte62","Texte64","Texte66","Te xte68","Texte70","Texte72","Texte74","Texte76","Texte78","Texte80","Texte82");
    var bNames = new Array("d1","d3","d4","d5","d6","d7","d8","d9","d10","d11","d12","d13","d14 ","d15","d16","d17");   // d1 is included because in some cases a student can finish in 1 day (short text);

  • How to Hide rows in ALV without affecting total sum at the end of table?

    Hi,
    I need some help in hiding particular rows in an ALV Grid without affecting the total sum at the end of the table. I am trying to hide the rows that have negative quantities, but I still need those values so that the user can still compute for the total sums. Can anyone help? Thanks.
    Joseph

    Hi,
    Hopw this way you can hide the rows in the GRID.
    DATA:
      ld_column      TYPE lvc_fname,
      ld_hide          TYPE abap_bool.
    FIELD-SYMBOLS:
      <ls_entry>     TYPE any,
      <ld_fld>         TYPE any.
      ld_column = 'COL_1'.  " column which you want to suppress if everything is zero
      ld_hide     = abap_true.  " = 'X';  default hide column
      LOOP at <gt_outtab> ASSIGNING <ls_entry>.
        ASSIGN COMPONENT (ld_column) OF STRUCTURE <ls_entry> TO <ld_fld>.
        IF ( <ld_fld>   > 0 ).
          ld_hide = abap_false.  " display column because at least single value > 0
          EXIT.  " leave LOOP
        ENDIF.
      ENDLOOP.
      READ TABLE gt_fcat INTO ls_fcat
                           WITH KEY fieldname = ld_column.
      IF ( syst-subrc = 0 ).
        ls_fcat-no_out = ld_hide.
        MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
      ENDIF.
    hop you will get the total with for those columns too.
    Regards,
    Madhavi

  • How to know the total purchase of the year.

    Hi all,
    One of our client wants to know the total purchase he made for the whole year for different materials only,i suggest them for ME51N but this gives PO based entry only which is different(higher)then actual purchase made,i think it should be MIRO based entery
    can anyone suggest is there any standard report in SAP or T.codee which give me total my client has made which hit the excise register also.
    Rishi Diwan

    Rishi,
    Check ME80 and MC$I transaction. This will help you get the details about purchasing quantities in a period.
    If helps reward points and close this thread.
    Regards
    TAJUDDIN

Maybe you are looking for

  • Every time I open a page, multiple pages open.

    Hi Ever since upgrading to 10.7 Lion whenever I open a file be it in Pages or Numbers or even preview, the last few pages also open.  I can't figure it out. Normally I'll use finder or double cick a file on my desktop.  How can I stop multiple pages

  • Network users can't move file to folder

    Hello, I'm working with a fresh lion server installation. Users have their home folder on the server. I filled default folders (desktop, documents, music...) with files and folder from snow leopard server Checked and double checked posix and ACL perm

  • XML failing with Rosettanet DTD

    Hi, We are using a PIP5D5 xml message for an interface. This message is structurally defined as per the DTD provided in the Rosettanet standards. But for some segments where multiples are allowed, we are trying to use an attribute to distinguish each

  • DBCA hangs with 'database not open'

    I've installed the Oracle 9i ver.2 Enterprise Edition software on a Tru64 Unix machine with 512MB of memory. The software was installed without any problems. However, while creating any database thru the Database Configuration Assistant it hangs on 4

  • RAC and High Availability

    Reading matt manfredonias Q/A about Load Balancing, I stil wonder, how the "outer world" sees the RAC. What happens in case of one of two nodes vanishing from the network. What if this node was the dispatcher? The user/application has to switch over