Max, sum function

I would like to get this result:
NAZWAWYDZIALU NAZWISKO
Organizacji i Zarządzania | Moskowitz
Elektrotechniki Informatyki | Crocitto
Mechaniczny | Walter
Inżynierii Procesowej | Mierzwa
Fizyki Technicznej | Olvsade
August displayed the names of employees who have the most papers.
I wrote the following query:
SELECT w.NazwaWydzialu, p.nazwisko
FROM wydzialy w,
          pracownicy p ,
          referatyPracownikow rp,
          referaty r,
          konferencje k
WHERE rp.idreferat = r.idReferatu and
               p.idPracownika = rp.idPracownika and
               r.idKonferencji = k.idKonferencji
HAVING count( * *)* = ( SELECT MAX ( sum (r.idReferatu))
                              FROM wydzialy w,
                                   pracownicy p,
                                   referatyPracownikow rp,
                                   referaty r,
                                   konferencje k
                              WHERE rp.idreferat = r.idReferatu and
                                        p.idPracownika = rp.idPracownika and
                                        r.idKonferencji = k.idKonferencji      
                              GROUP BY r.idReferatu)
     GROUP BY w.NazwaWydzialu, p.nazwisko ;
returns 0 rows :(
Please kindly information, whether well-written query.
Tables:
CREATE TABLE publikacje (
     idPublikacji number(4) CONSTRAINT kl_glowny_pub PRIMARY KEY ,
     tytulPublikacji varchar(30),
     nazwaWydawnictwa varchar(30),
     dataPublikacji date
CREATE TABLE konferencje (
     idKonferencji number(4) CONSTRAINT kl_glowny_konf PRIMARY KEY ,
     NazwaKonferencji varchar(30),
     lokalizacja varchar(30),
     dataPoczatkowa date,
     dataZakonczenia date
CREATE TABLE przedmioty (
     idPrzedmiotu number(4) CONSTRAINT kl_glowny_przed PRIMARY KEY ,
     nazwaPrzedmiotu varchar(30)
CREATE TABLE FormyPrzedmiotow (
     idFormyPrzed number(4) CONSTRAINT kl_glowny_formyPrzed PRIMARY KEY,
     idPrzedmiotu CONSTRAINT kl_obcy_przed REFERENCES przedmioty(idPrzedmiotu),
     forma varchar(30),
     semestr number(1),
     rokAkademicki date
CREATE TABLE uczelnie (
     iduczelni number(4) CONSTRAINT kl_glowny_ucze PRIMARY KEY ,
     NazwaUczelni varchar(30),
     adres varchar(30),
     kodpocztowy varchar(6),
     miasto varchar(30),     
     NrTelefonu number(10),
     NIP_ucz     number(10)
CREATE TABLE wydzialy (
     idWydzialu number(4) CONSTRAINT kl_glowny_wydz PRIMARY KEY ,
     NazwaWydzialu varchar(30),
     Iduczelni CONSTRAINT kl_obcy_ucz REFERENCES uczelnie(iduczelni)
CREATE TABLE katedry (
     idkatedry number(4) CONSTRAINT kl_glowny_kated PRIMARY KEY ,
     Nazwakatedry varchar(30),
     IdWydzialu CONSTRAINT kl_obcy_wydz REFERENCES wydzialy(idWydzialu)     
CREATE TABLE pracownicy (
     idPracownika number(4) CONSTRAINT kl_glowny_prac PRIMARY KEY ,
     nazwisko varchar(30),
     imie varchar(30),
     tytul_naukowy varchar(30),
     adres varchar(30),
     kodPoczatkowy varchar(6),
     miasto varchar(30),
     telefonDomowy number(10),
     dataUrodzenia date,
     ID_katedry CONSTRAINT kl_obcy_kated REFERENCES katedry(idkatedry)
CREATE TABLE referaty (
     idReferatu number(4) CONSTRAINT kl_glowny_ref PRIMARY KEY ,
     tytulReferatu varchar(30),
     dataReferatu date,
     idKonferencji CONSTRAINT kl_obcy_konf REFERENCES konferencje(idKonferencji)
CREATE TABLE referatyPracownikow (
     idreferat CONSTRAINT kl_obcy_ref REFERENCES referaty(idReferatu),
     idPracownika CONSTRAINT kl_obcy_prac REFERENCES pracownicy(idPracownika)
CREATE TABLE publikacjePracownikow (
     idPracownika CONSTRAINT kl_obcy_prac2 REFERENCES pracownicy(idPracownika),
     idPublikacji CONSTRAINT kl_obcy_pub REFERENCES publikacje(idPublikacji)
CREATE TABLE przedmiotyProwadzone (
     idFormyPrzed CONSTRAINT kl_obcy_formyPrzed2 REFERENCES FormyPrzedmiotow(idFormyPrzed),
     idPracownika CONSTRAINT kl_obcy_prac3 REFERENCES pracownicy(idPracownika),
     LiczbaGodz number(10)
);

INSERT INTO publikacje VALUES (1, 'tytulPublikacji 1', 'nazwaWydawnictwa 1',TO_DATE('29-APR-2011 20:17:26','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO publikacje VALUES (2, 'tytulPublikacji 2', 'nazwaWydawnictwa 2',TO_DATE('25-MAR-2012 22:15:06','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO publikacje VALUES (3, 'tytulPublikacji 3', 'nazwaWydawnictwa 3',TO_DATE('11-JAN-2008 09:14:08','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO publikacje VALUES (4, 'tytulPublikacji 4', 'nazwaWydawnictwa 4',TO_DATE('09-FEB-2009 10:14:13','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO publikacje VALUES (5, 'tytulPublikacji 5', 'nazwaWydawnictwa 5',TO_DATE('23-MAY-2010 17:16:23','DD-MON-YYYY HH24:MI:SS'));
INSERT INTO konferencje VALUES (1, 'konferencje 1', 'Warszawa' ,TO_DATE('29-APR-2011 09:17:26','DD-MON-YYYY HH24:MI:SS') ,TO_DATE('29-APR-2011 20:17:26','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO konferencje VALUES (2, 'konferencje 2', 'Warszawa' ,TO_DATE('25-MAR-2012 10:15:06','DD-MON-YYYY HH24:MI:SS') ,TO_DATE('29-APR-2011 17:17:26','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO konferencje VALUES (3, 'konferencje 3', 'Warszawa' ,TO_DATE('11-JAN-2011 09:14:08','DD-MON-YYYY HH24:MI:SS') ,TO_DATE('11-JAN-2011 18:14:08','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO konferencje VALUES (4, 'konferencje 4', 'Warszawa' ,TO_DATE('09-FEB-2012 10:14:13','DD-MON-YYYY HH24:MI:SS') ,TO_DATE('09-FEB-2012 16:14:13','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO konferencje VALUES (5, 'konferencje 5', 'Warszawa' ,TO_DATE('23-MAY-2012 10:10:23','DD-MON-YYYY HH24:MI:SS') ,TO_DATE('23-MAY-2012 17:16:23','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO przedmioty VALUES (1, 'Sztuczna inteligencja' );
INSERT INTO przedmioty VALUES (2, 'Bazy danych' );
INSERT INTO przedmioty VALUES (3, 'Inzynieria oprogramowania' );
INSERT INTO przedmioty VALUES (4, 'Matematyka' );
INSERT INTO przedmioty VALUES (5, 'Algorytmy i struktury danych' );
INSERT INTO FormyPrzedmiotow VALUES (1, 1, 'forma 1', 1, TO_DATE('16-MAY-2010 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (2, 1, 'forma 2', 2, TO_DATE('16-JAN-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (3, 2, 'forma 3', 3, TO_DATE('16-APR-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (4, 2, 'forma 4', 4, TO_DATE('16-APR-2011 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (5, 3, 'forma 5', 5, TO_DATE('16-JUN-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (6, 4, 'forma 6', 6, TO_DATE('16-FEB-2011 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (7, 5, 'forma 7', 7, TO_DATE('16-MAY-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (8, 3, 'forma 8', 1, TO_DATE('16-APR-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (9, 1, 'forma 9', 3, TO_DATE('16-JAN-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO FormyPrzedmiotow VALUES (10, 2, 'forma 10',2, TO_DATE('16-FEB-2012 09:00:00','DD-MON-YYYY HH24:MI:SS') );
INSERT INTO uczelnie VALUES (1, 'Politechnika Warszawska' , 'ul. Matuszewskiego 82; ','06-300', 'Przasnysz', 7582313 , 9084546646);
INSERT INTO uczelnie VALUES (2, 'Politechnika Wroclawska' , 'ul. Polna 7/6; ','09-221', 'Poznan', 7562213 , 9014546645);
INSERT INTO uczelnie VALUES (3, 'Politechnika Gdanska' , 'ul. Figarskiego 6; ','08-675', 'Kielce', 7362316 , 2084244444);
INSERT INTO uczelnie VALUES (4, 'Politechnika Slaska' , 'ul. Dluga 51; ','08-675', 'Poznan', 7362217 , 1222521111);
INSERT INTO uczelnie VALUES (5, 'Politechnika Łódzka' , 'ul. Macieja 31; ','08-675', 'Poznan', 7568288 , 1014546778);
INSERT INTO wydzialy VALUES (1,'Organizacji i Zarządzania', 2 );
INSERT INTO wydzialy VALUES (2,'Elektrotechniki Informatyki', 1 );
INSERT INTO wydzialy VALUES (3,'Mechaniczny' , 5);
INSERT INTO wydzialy VALUES (4,'Inzynierii Procesowej', 1 );
INSERT INTO wydzialy VALUES (5,'Fizyki Technicznej' ,3);
INSERT INTO katedry VALUES (1, 'Zarządzania',2 );
INSERT INTO katedry VALUES (2, 'Elektrotechniki',1 );
INSERT INTO katedry VALUES (3, 'Mechaniczna' ,5);
INSERT INTO katedry VALUES (4, 'Inzynierii',1 );
INSERT INTO katedry VALUES (5, 'Fizyki' ,3);
INSERT INTO pracownicy VALUES (1,'Crocitto', 'Fred' ,'doktor', 'ul. Polna 7/6; ','09-221', 'Poznan', 5352217 , TO_DATE('16-MAY-1990 09:00:00','DD-MON-YYYY HH24:MI:SS'), 1);
INSERT INTO pracownicy VALUES (2,'Landry', 'Laetia.' ,'doktor', 'ul. Dluga 51; ','08-675', 'Poznan', 2252259 , TO_DATE('09-FEB-1970 05:20:08','DD-MON-YYYY HH24:MI:SS'), 2);
INSERT INTO pracownicy VALUES (3,'Enison', 'Laetia' ,'doktor', 'ul. Macieja 31; ','08-675', 'Poznan', 8262215 , TO_DATE('19-JAN-1970 10:00:09','DD-MON-YYYY HH24:MI:SS'), 3);
INSERT INTO pracownicy VALUES (4,'Moskowitz','Angel' ,'magister', 'ul. Figarskiego 6; ','08-675', 'Kielce', 7362218 , TO_DATE('17-FEB-1970 03:10:10','DD-MON-YYYY HH24:MI:SS'), 5);
INSERT INTO pracownicy VALUES (5,'Olvsade', 'Judith' ,'profesor', 'ul. Figarskiego 6; ','08-675', 'Warszawa', 6362187 , TO_DATE('11-MAR-1962 12:08:11','DD-MON-YYYY HH24:MI:SS'), 4);
INSERT INTO pracownicy VALUES (6,'Mierzwa', 'Catherine','profesor', 'ul. Dluga 01; ','08-685', 'Warszawa', 7462115 , TO_DATE('14-JAN-1970 13:00:01','DD-MON-YYYY HH24:MI:SS'), 2);
INSERT INTO pracownicy VALUES (7,'Sethi', 'Judy' ,'doktor habilitowany', 'ul. Polna 6; ','09-281', 'Poznan',7462317, TO_DATE('23-MAR-1979 15:06:23','DD-MON-YYYY HH24:MI:SS'), 5);
INSERT INTO pracownicy VALUES (8,'Walter', 'Larry' ,'doktor habilitowany', 'ul. Macieja 31; ','08-675', 'Poznan',7345218, TO_DATE('20-FEB-1959 01:04:07','DD-MON-YYYY HH24:MI:SS'), 1);
INSERT INTO referaty VALUES (1, 'baza Acces',TO_DATE('13-MAR-2012 10:05:06','DD-MON-YYYY HH24:MI:SS'),2 );
INSERT INTO referaty VALUES (2, 'Eksploracja danych',TO_DATE('09-MAY-2012 12:00:06','DD-MON-YYYY HH24:MI:SS'),1 );
INSERT INTO referaty VALUES (3, 'Podstawy rysunku technicznego' ,TO_DATE('05-FEB-2012 14:10:06','DD-MON-YYYY HH24:MI:SS'),5);
INSERT INTO referaty VALUES (4, 'Animacja i wideo',TO_DATE('27-FEB-2012 12:10:06','DD-MON-YYYY HH24:MI:SS'),1 );
INSERT INTO referaty VALUES (5, 'Szkolenie BHP' ,TO_DATE('21-MAY-2012 16:10:06','DD-MON-YYYY HH24:MI:SS'),3);
INSERT INTO referatyPracownikow VALUES (1, 2 );
INSERT INTO referatyPracownikow VALUES (2, 1 );
INSERT INTO referatyPracownikow VALUES (4 , 6 );
INSERT INTO referatyPracownikow VALUES (4, 1 );
INSERT INTO referatyPracownikow VALUES (5, 3 );
INSERT INTO publikacjePracownikow VALUES (1, 1 );
INSERT INTO publikacjePracownikow VALUES (2, 3 );
INSERT INTO publikacjePracownikow VALUES (3, 5 );
INSERT INTO publikacjePracownikow VALUES (4, 1 );
INSERT INTO publikacjePracownikow VALUES (5, 4 );
INSERT INTO przedmiotyProwadzone VALUES (1, 1 ,160 );
INSERT INTO przedmiotyProwadzone VALUES (2, 3 ,120 );
INSERT INTO przedmiotyProwadzone VALUES (3, 5 ,140 );
INSERT INTO przedmiotyProwadzone VALUES (4, 1 ,120 );
INSERT INTO przedmiotyProwadzone VALUES (5, 4 ,100 );

Similar Messages

  • Sum() function not working properly. Instead of summing, its showing total count of the rows

    We have migrated one application from .net framework 1.0 to .net framework  2 (from Visual studio 2003 to Visual STUDIO 2005). Now after migration we are facing some problem related to the sum function in Crystal report 10. It is not working properly.
    So we migrated to Crystal report XI release 2 (though still using evaluation version for testing purpose), the problem is not yet resolved.
    The problem we are facing is while using the summary in the group field, it is showing the number of rows instead of the sum of the values.
    We have checked the same with min-max functions, and it is working properly with those.
    We have tried to make the sum by formula field. In such case, it is not showing any syntactical error but at execution time, it is throwing an error saying "A number field or currency amount field is required here".
    In the  the report the datatype of the field on which we are applying the sum function, is number, and in the table from where the data is fetched, the datatype is numeric(9,6).
    Any idea why sum function is not working ?
    I was browsing the net and saw running totals can be a work around for such summation issues in Crystal Report XI.
    Can you please provide insight of how to implement running totals for summation purpose in solving such issues.

    Hi,
    Running totals are more accurate than Summary Totals in Crystal.  Why? ...ask Crystal.  Anyway, just right click on Running Totals, create a new one, and enter you fields, etc. For group totals, it gives you a place to reset the totals for each group, etc.  Pretty self explainatory. 
    Jim

  • Problem with group by and sum function

    In one of the report I'm using grioup by clause on one column. However when I use this function the sum function on other column is not working.
    Any idea how we can resolve this?

    Hi Tintin,
    Follow the below steps:
    1) On the order number column formula, use the max function.
    2) Duplicate the revenue column in the RPD, set the aggregation to sum and level to transaction. This will give you the sum of all the orders in a particular trasaction, where as in report you will see only the max account number.
    Assign points if helpful.
    Thanks,
    -Amith.

  • Sum function not working properly in Crystal XI. Its showing total count of the values

    We have migrated one application from .net framework 1.0 to .net framework  2 (from Visual studio 2003 to Visual STUDIO 2005). Now after migration we are facing some problem related to the sum function in Crystal report 10. It is not working properly.
    So we migrated to Crystal report XI release 2 (though still using evaluation version for testing purpose), the problem is not yet resolved.
    The problem we are facing is while using the summary in the group field, it is showing the number of rows instead of the sum of the values.
    We have checked the same with min-max functions, and it is working properly with those.
    We have tried to make the sum by formula field. In such case, it is not showing any syntactical error but at execution time, it is throwing an error saying "A number field or currency amount field is required here".
    In the  the report the datatype of the field on which we are applying the sum function, is number, and in the table from where the data is fetched, the datatype is numeric(9,6).
    Any idea why sum function is not working ?
    I was browsing the net and saw running totals can be a work around for such summation issues in Crystal Report XI.
    Can you please provide insight of how to implement running totals for summation purpose in solving such issues.

    Are you seeing this happen in the Crystal designer as well, outside of any .NET application?

  • Error when using SUM function in Excel template

    I am trying to use the XDO_METADATA to create a sum of a column from my XML data and I am getting the following error in the Template Viewer:
    [111412_104246459][][PROCEDURE] Log Level is changed to PROCEDURE
    [111412_104246553][oracle.xdo.common.xml.XSLTWrapper][ERROR] XSL error:
    Time: 0.125 sec.
    FO Formatting failed.
    <Line 317, Column 116>: XML-23029: (Error) FORG0001: invalid value for cast/constructor
    @Line 317 ==> <Cell Index="2" Style="R7C3" Field="XDO_?SUM_V_CR_MO_IDD1?"><xsl:value-of select="sum(.//G_CR_MST_D/V_CR_MO_IDD)"/>
    when I use:
    XDO_?SUM_V_CR_MO_IDD1?     <?sum(.//G_CR_MST_D/V_CR_MO_IDD)?>
    or
    [111412_104048508][][PROCEDURE] Log Level is changed to PROCEDURE
    [111412_104048554][oracle.xdo.common.xml.XSLTWrapper][ERROR] XSL error:
    Time: 0.078 sec.
    FO Formatting failed.
    <Line 317, Column 105>: XML-23029: (Error) FORG0001: invalid value for cast/constructor
    @Line 317 ==> <Cell Index="2" Style="R7C3" Field="XDO_?SUM_V_CR_MO_IDD1?"><xsl:value-of select="sum(.//V_CR_MO_IDD)"/>
    when I use:
    XDO_?SUM_V_CR_MO_IDD1?     <?sum(.//V_CR_MO_IDD)?>
    I believe the XSL to be correct because when I change it to a count it works and when I go into BI Publisher 11g and create the query in the data model and then create a summary from it, the summary is created.
    Can anyone help?

    I went back to basics and created reports (via EXCEL templates) like I was asking based on good old EMP and DEPT and I found exactly the same problems I was mentioning. I looked at the templates provided but they were not calculating totals, like me they were selecting them and then just displaying them on the page.
    Anyway, I have narrowed it down to the fact that when you do aggregates like sum(.//SAL) this works if you have a salary for every value. I did an outer join with DEPT so I did have empty rows and why I still experienced the problems.
    Basically XSL does not like adding (including using the sum function) values that effectively have nulls in them which is why I get the cast/constructor errors because it is trying to turn a NaN value to a number and does not (or cannot) do it.
    You need to either have a value in every row of your column (maybe possible by selecting nvl in your query) and make sure that you check the "create empty nodes" checkbox in the data model of BI Publisher.,
    the other solution is an xsl solution where you would have to make sure that you only added non null values and for that you would have to investigate xsl blogs.
    It is, by the way, why my count worked because it is just counting that the record exists it does not care what the element content is or isn't.
    Closing thread.

  • Issues using SUM Function in query

    I have pasted two queries Query1 (calculating counts for total_ships and ships_released) and Query2 (calculating the two same counts and then calculating SUM for total_shipments and I am having problem in this)
    Query 1:
    select  b.loc , b.week, b.vvalue2, b.Total_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
    from (
          SELECT l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date ,  count(distinct s.ship_id ) as ships_rel_total
          FROM ship s, loct l,
             ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
          ) A,
    ( SELECT distinct l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
          FROM ship s, loct l,
              ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by c.loc , c.week , c.vvalue2  ) B
    where a.loc (+) = b.loc
    and a.vvalue2  (+) = b.vvalue2
    order by b.loc, b.week , b.vvalue2,a.up_date; Query 1 Output:
    *OUTPUT*
    LOC         WEEK          VALUE2        TOTAL_SHIPS       DATEE         TOtAL_SHIPS_RELEASED
    AA          111              BB              12                  10-05-12            2
    AA          111              BB              12                  11-05-12            4
    AA          111              CC              2                    14-05-12            1Then I added sum function for total_ships and its not giving me result what I need :(
    Query 2:
    select  b.loc , b.week, b.vvalue2, b.sum_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
    from (
          SELECT l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date ,  count(distinct s.ship_id ) as ships_rel_total
          FROM ship s, loct l,
             ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
    ) A,
    ( Select  c.loc, c.week , c.vvalue2 ,  sum(c.total_ships) sum_ships 
    from
        ( SELECT distinct l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
          FROM ship s, loct l,
              ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1 , sr.vvalue2  ) C
    Group by c.loc , c.week , c.vvalue2  ) B
    where a.loc (+) = b.loc
    and a.vvalue2  (+) = b.vvalue2
    order by b.loc, b.week , b.vvalue2,a.up_date;  my query is giving me this :(
    Query 2 Output:
    LOC         WEEK          VALUE2        *SUM_SHIPS*       DATEE         TOtAL_SHIPS_RELEASED
    AA          111                BB              26                 10-05-12            2
    AA          111                BB              26                 11-05-12            4
    AA          111                CC              26                 14-05-12            1
    But I need a result like this:
    LOC         WEEK          VALUE2        SUM_SHIPS       DATEE         TOtAL_SHIPS_RELEASED
    AA          111                BB              14              10-05-12            2
    AA          111                BB              14              11-05-12            4
    AA          111                CC              14              14-05-12            1

    Hi,
    It sounds like you have a Fan Trap , where a one-to-many relationship is causing some items to be counted many times.
    The usual solution is to compute the aggregates before doing the one-to-many join. Analytic functions may make this simpler.
    Sorry, I can't show you exactly how to do it without the exact data.
    Post CREATE TABLE and INSERT statements for all tables involved, and also post the results you want from that data (if different from what you've already posted).
    Explain, using specific examples, how you get those results from that data.
    Simplify the problem as much as possible. If the problem only concerns the total_ships column, then only post the data needed to compute total_ships. This includes all the columns involved in the joins and GROUP BY clauses.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Max Date Function

    Hi,
    I have the following columns in a report:
    Vendor Name
    Trade date
    Prod Desc
    Order Type
    Qty
    Gross Amt
    I need to display only those rows where trade date = max(trade date).
    I am aware of the MAX analytic function, but it keeps giving me an error.
    Could someone please let me know how to achieve this scenario.
    Thanks.

    Hi
    As pupppethead mentioned, it doesn't look as though you need a PARTITION BY clause.
    A straight MAX(Trade Date) OVER () = Trade Date should suffice. The OVER() tells Discoverer to look at all dates in the query. You will only need a PARTITION BY if you are using Page Items or Group Sorts and you wanted a different date in each set.
    By the way, as a word of warning, be very careful not to name items in folders or workbooks using Oracle reserved words. Naming an item as Desc is dangerous because that is the name of the descending switch in an ORDER BY clause of an analytic function. Thus, if you have for example something called ITEM DESC and try to do this:
    RANK() OVER(ORDER BY ITEM DESC) you will have serious problems because the database (not Discoverer) will think you want to sort ITEM descending. Either ITEM does not exist and you will get an error or it does exist and you will end up with the sort on the wrong item.
    Imagine also if you named something ORDER BY and then place this in a PARTITION BY clause like this:
    MAX(Trade Date) OVER (PARTITION BY ORDER BY)
    Interesting conundrum, don't you think?
    Best wishes
    Michael

  • Strange error in SUM function in XI

    Hi geeks,
    We are encountering a strange issue in SUM functionality in XI.
    The Scenario is :
    We have a pipe delimited source file and INVOIC01 idoc as target.  each line in the source file will create a segment E1EDP01 in the target IDOC.
    All the values given in the file should be summed and mapped to E1EDS01 segment in the idoc.
    In one such strange case the sum of the values generated by the SUM function in XI is 2 cents lesser what we manually calculate using Calculator or Excel . There are about 100+ items in the file.  This not the case always it happens once in a while.
    Have any of you faced such strange errors. If yes please throw some light on the solution for this issue.
    Thanks,
    Noorul

    Hi folks,
    Thanks for your help. I solved this by writing my own code
    double sum = 0;
    String value;
    for (int i= 0; i< a.length; i++)
    sum = sum + Double.parseDouble(a<i>);
    value = Double.toString(sum);
    BigDecimal  bg1 = new BigDecimal(value);
    BigDecimal bg2 = bg1.setScale(2, BigDecimal.ROUND_HALF_DOWN);
    result.addValue(bg2.toString());

  • How can I sum up raws? the sum function seems to work for columns only and right now I have to create a separate formula for each raw

    How can I sum up raws? the Sum function seems to work only on columns. Right now I have to create a separate formula for each raw

    Hi dah,
    "Thanks, but can I do one formula for all present and future raws? as raws are being added, I have to do the sum function again and again"
    You do need a separate formula for each group of values to be summed.
    If the values are in columns, you need a copy of the formula for each column.
    If the values are in rows, you need a copy of the formula for for each row.
    If you set up your formulas as SGIII did in his example (shown below), where every non-header row has the same formula, Numbers will automtically add the formula to new rows as you add them.
    "Same formula" in this context means exactly the same as all the formulas above, with one exception: the row reference in each formula is incremented (by Numbers) to match the row containing the formula.
    Here the formula looks like this in the three rows shown.
    B2: =SUM(2)
    B3: =SUM(3)
    B4: =SUM(4)
    That pattern will continue as rows are added to the table.
    Also, because the row token (2) references all of the non-header cells in row 2, the formula will automatically include new columns as they are added to the table.
    Regards,
    Barry

  • How to correct XML Output in Cross Tab Template for sum function?

    I have designed a Cross Tab Template to summarize R12 Account Analysis data by Period by Party_name. The template is doing what I want it to do with the exception of amount. I have a function in the sum(accounted_net) field and it will only display 0.00 even though I know there are actual amount. Can someone help in looking at my template to see what I have done wrong?
    Here is the sum funciton.
    <?if:count(current-group()[CCID_SOURCE=$ABC])?><?sum(current-group()[CCID_SOURCE=$ABC]/ACCOUNTED_NET)?> <?end if?>
    CCID_SOURCE is an element I created in XML to concatnate CCID and Party_name for grouping. $ABC is a variable that I defined for "CCID_SOURCE" to check if there is null value for a specific ccid_party. If it's null, it won't do the sum function, otherwise it will sum the accounted_net for the period_name, party_name.
    Thank you for your help.
    Stacey

    Figured this out on our own

  • COUNT() and SUM() function it not working in XDO file.

    Hi ,
    I am getting one error. Count and sum function not working proper.
    For example :
    Department 10 have 3 employee and total salary is 8750. But my report returning total employee 1 and total salary 5000
    10
    Ename Sal
    KING 5000
    CLARK 2450
    MILLER 1300
    ==================
    total employee : 1
    total salary : 5000
    Kindly help me solve this problem.
    <dataTemplate name="TEXT">
    <properties>
    <property value="upper" name="xml_tag_case" />
    </properties>
    <lexicals>
    </lexicals>
    <dataQuery>
    <sqlstatement name="Q_TEMP">
    <![CDATA[SELECT DEPTNO,DNAME,LOC FROM DEPT]]>
    </sqlstatement>
    <sqlstatement name="Q_TEMP1">
    <![CDATA[SELECT ENAME,HIREDATE,SAL FROM EMP WHERE DEPTNO = :DEPTNO]]>
    </sqlstatement>
    </dataQuery>
    <datastructure>
    <GROUP name="G_1" source="Q_TEMP">
    <element value="DEPTNO" name="DEPTNO" />
    <element value="DNAME" name="DNAME" />
    <element value="LOC" name="LOC" />
    <GROUP name="G_2" source="Q_TEMP1">
    <element value="ENAME" name="ENAME" />
    <element value="SAL" name="SAL" />
    <element value="G_2.ENAME" name="TOTL_DETAILS" dataType="number" function="COUNT()" />
    <element value="G_2.SAL" name="TOTL_SAL" function="SUM()"/>
    </GROUP>
    </GROUP>
    </datastructure>
    </dataTemplate>
    Thanks
    Yudhi

    Please have the data structure as below:
    <datastructure>
    <GROUP name="G_1" source="Q_TEMP">
    <element value="DEPTNO" name="DEPTNO" />
    <element value="DNAME" name="DNAME" />
    <element value="LOC" name="LOC" />
    <GROUP name="G_2" source="Q_TEMP1">
    <element value="ENAME" name="ENAME" />
    <element value="SAL" name="SAL" />
    *</GROUP>*
    *<element value="G_2.ENAME" name="TOTL_DETAILS" dataType="number" function="COUNT()" />*
    *<element value="G_2.SAL" name="TOTL_SAL" function="SUM()"/>*
    *</GROUP>*
    </datastructure>
    Aggregate functions to be placed at the level you require it. Here you need at G_1, so place it there.

  • SUM function issue

    Hi everyone,
    I have a problem with SUM function in SQL query on Oracle 11g database. Maybe you will be able to help me.
    Problem:
    I want to shows summary costs for shipments separately for each service provider and for each month they did the shipments.
    Data is stored in SHIPMENT AND SHIPMENT_COST table as shown below. The problem is that summary function I use sums base costs (marked as B in SHIPMENT_COST table) for each accessorial cost (marked as A in SHIPMENT_COST table). In example for shipment 10005031 we have 4 accessorial costs so it shows 6120 in BASE_COST column. I tried to use distinct in summary but then we have a problem with shipment id 201307133713_0383 which has 3 base costs equal to 221.54 so with distinct it will show 221.54 instead of 221.54x3.
    SHIPMENT table:
    START_TIME               SHIPMENT_GID               SERVPROV_GID
    2013-06-25                    10005031                         T222176
    2013-06-15                    201307133713_0383          T76180
    SHIPMENT_COST table:
    SHIPMENT_GID                        COST                                       COST_TYPE
    10005031                                 1530                                        B
    10005031                                  30.6                                        A
    10005031                                  120                                         A
    10005031                                  400                                         A
    10005031                                  100                                         A
    201307133713_0383                   221.54                                    B
    201307133713_0383                   221.54                                    B
    201307133713_0383                   221.54                                    B
    RESULT table:
    SHIPMENT_START_DATE
    SERVPROV
    BASE_COST
    CLAIM_COST
    06/2013
    T76180
    664.62
    null
    06/2013
    T222176
    6120
    650.6
    Query:
    SELECT DISTINCT TO_CHAR(SH.START_TIME,'MM/YYYY') AS SHIPMENT_START_DATE,
            SH.SERVPROV_GID AS SERVPROV,
            SUM(SHCOST.COST) AS BASE_COST,
            SUM(SHCOST_CLAIM.COST) AS CLAIM_COST
    FROM    SHIPMENT SH,
            SHIPMENT SHC
            LEFT OUTER JOIN SHIPMENT_COST SHCOST ON (SHC.SHIPMENT_GID = SHCOST.SHIPMENT_GID AND SHCOST.COST_TYPE = 'B'),
            SHIPMENT SHC_CLAIM
            LEFT OUTER JOIN SHIPMENT_COST SHCOST_CLAIM ON (SHC_CLAIM.SHIPMENT_GID = SHCOST_CLAIM.SHIPMENT_GID AND SHCOST_CLAIM.COST_TYPE = 'A')
    WHERE 1=1
            AND SHC.SHIPMENT_GID = SH.SHIPMENT_GID
            AND SHC_CLAIM.SHIPMENT_GID = SH.SHIPMENT_GID
            AND    SH.SHIPMENT_GID IN ('10005031','201307133713_0383')
            GROUP BY TO_CHAR(SH.START_TIME,'MM/YYYY'),
            SH.SERVPROV_GID
    Best Regards,
    Łukasz

    with SHIPMENT (START_TIME,SHIPMENT_GID,SERVPROV_GID) as
    select to_date('2013-06-25','yyyy-mm-dd'),'10005031','T222176' from dual union all
    select to_date('2013-06-15','yyyy-mm-dd'),'201307133713_0383','T76180' from dual
    SHIPMENT_COST(SHIPMENT_GID,COST,COST_TYPE)
    as
    select '10005031','1530','B' from dual union all
    select '10005031','30.6','A' from dual union all
    select '10005031','120','A' from dual union all
    select '10005031','400','A' from dual union all
    select '10005031','100','A' from dual union all
    select '201307133713_0383','221.54','B' from dual union all
    select '201307133713_0383','221.54','B' from dual union all
    select '201307133713_0383','221.54','B' from dual
    select *
      from (select to_char(t.START_TIME, 'mm/yyyy'),
                   t.SERVPROV_GID,
                   c.COST,
                   c.COST_TYPE
              from SHIPMENT t
              join SHIPMENT_COST c
                on t.SHIPMENT_GID = c.SHIPMENT_GID)
    pivot(sum(COST) for COST_TYPE in('A' CLAIM_COST,'B' BASE_COST))
    TO_CHAR(T.START_TIME,'MM/YYYY'
    SERVPROV_GID
    CLAIM_COST
    BASE_COST
    06/2013
    T76180
    664.62
    06/2013
    T222176
    650.6
    1530
    Ramin Hashimzade

  • Reg: sum() function in XML

    HI frs,
    while using sum function in Xml.not getting correct output.
    for ex:
    i have created report with emp table.
    load the xml into MS-Word.
    i want to sum total of salary of employees.
    i used SUM() function to calculate but in output it adds twice the first value and adds the rest
    for ex :
    these are values
    200
    300
    500
    i am gettting total like 1200 actually it should be 1000.
    it adds like 200+200+300+500
    why is it so.
    Regards
    Rajesh

    Hi,
    I have a problem with the 'l_booklist', I declare it as 'l_booklist  TYPE REF TO if_ixml_node' like in the interface but a shortdump comes up. must it be filled?
    greets
    Thomas

  • Help with SUM function ??

    Hi,
    I am trying to build a SUM function into the following SELECT statement;
    SELECT   emp_code "EmployeeCode", trn_date "TransactionDate", project "ProjectCode",
    phase_code "PhaseCode", task_code "TaskCode", reg_hrs "RegularHoursAmt", rate_reg "RegularHoursRate", ot_hrs "OvertimeHoursAmt", rate_ot "OvertimeHoursRate"
    Currently when i do the extract to xls I manually compile the "RegularHoursAmt" and "RegularHoursRate" manually and it's quite a task. I'm sure it can be completed in teh SELECT but I'm not clear on how and it's been quite some time since my last foray into SQL. Any assistance appreciated.
    I need to sum "RegularHoursAmt" and "RegularHoursRate"
    per "EmployeeCode"
    by "TransactionDate"
    with unique combo of "ProjectCode", "PhaseCode", "TaskCode"
    Cheers, Peter

    Hi, Peter,
    PJS5 wrote:
    Thanks Frank for the quick response. Ok, here goes;
    The TABLES already exist and I am only pulling the data for the columns in my SELECT statement so no CREATE of INSERT as such.Post CREATE TABLE and INSERT statements so that the people who want to help you can re-create the problem and test their ideas.
    The data is in Oracle 10g 10.1.0.2.0Perfect!
    So you want totals that represent the entire day for a given employee.
    Yes, but rows are by the unique combo per employee of "ProjectCode", "PhaseCode", "TaskCode"So a row of output will represent a distinct combination of employee, day, ProjectCode, PhaseCode and TaskCode, and that one output row may correspond to more than one row of input; is that right?
    eg Tom works on 4 unique "ProjectCode/PhaseCode/TaskCode" efforts on "TransactionDate"What does "effort" mean here? If I could look at some actaul data (or actual fake data; don't post anything like real credit card numbers) and the results you want from that data, perhaps it would be clear.
    One of those unique "ProjectCode/PhaseCode/TaskCode" efforts however has 3 timesheet entries as he has added unique Descriptions of what his efforts were aimed at achieving.
    We are not extracting the Descriptions and thereby want to SUM those 3 timesheet entries into one row.
    Do you also want a total for each employee, over all days? No thanks
    Do you want a grand total for all employees and all days? No thanks
    Do you want the totals on the same output rows as your current reuslts? That would be handy
    If so, use the analytic SUM function. I'm not familiar with this
    Do you want separate rows for the the totals? That could helpPost the exact results you want from a small set of given data. It's fine to describe the results, as you did above, but describe them in addition to (not instead of) actually showing them.
    Does that make my questions easier to follow?It looks good, but without some sample data and the results you want from that data, I can't say for sure.
    Please post CREATE TABLE and INSERT statements (relevant columns only) for a little sample data, so that I (and the others who want to help you) can see exactly what your tables are like, and actually try our solutions. Simplify as much as possible. For example, if the data is actually coming from a multi-table join, but you already know how to join all the tables perfectly, then pretend all the data is in one table, and post CREATE TABLE and INSERT statements for that one table that looks sort of like your current result set. Post just enough data to show what you want to do. Based on what you've said so far, I'm guessing that 10 to 20 rows of raw data, resulting in 3 to 7 rows of output could give a nice example.
    Also, post the exact results you want from the sample data you post. Explain, with specific examples, how you get those results from that data.
    If parts of your desired output are optional (that is, if some parts "would be handy" or "could help") then post a couple of different sets of results from the same data, and explain, something like this:
    "What I'd really love to get for results is" ...
    but, if that makes things really complicated or inefficient, I don't absolutely need ... or ...,
    so I'd settle for these results: ..."
    I know it's a lot of work to post all this information, but it's really necessary. If I could help you without making you do all this, then I would. Unfortunately, I really don't have a good idea of where you're coming from or where you want to go.
    Edited by: Frank Kulash on Oct 19, 2010 8:01 PM

  • How can I use SUM function to calculate # of employees in the comp.&deptnt?

    I've got two tables: employee & department. I am trying to calculate total employees by department and total employees by the entire company. I know I need to use SUM function, but I only can calculate total employees by department & by company separately. I need to get this output:
    DEPT_NAME     DEPT_TOTAL_SALARY         COMPANY_TOTAL_SALARY
    RESEARCH                  10875                        29025
    SALES                      9400                        29025   
    ACCOUNTING                 8750                        29025     
    This is my code:
    SELECT department_name, SUM(salary) as total_salary
    FROM employee, department
    WHERE employee.department_id = department.department_id
    GROUP BY department_name;
    SELECT SUM(salary)
    FROM employee;
    Can somebody help please?
    Thank you in advance.Edited by: user13675672 on Jan 30, 2011 2:29 PM
    Edited by: user13675672 on Jan 30, 2011 2:31 PM

    Hi, Peter
    Peter Gjelstrup wrote:
    ... There might be a smarter way, with no re-select.You're right, as usual.
    SELECT       d.dname
    ,       SUM (e.sal)               AS dept_tot_sal
    ,       SUM (SUM (e.sal)) OVER ()     AS comp_tot_sal
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    GROUP BY  d.dname
    ;Analytic functions are computed after aggregate functions, so an aggregate function can be nested inside an analytic function.
    Another way (without a sub-query, at least) would be SELECT DISTINCT, with only analytic functions.
    SELECT DISTINCT
           d.dname
    ,       SUM (e.sal) OVER (PARTITION BY  d.dname)     AS dept_tot_sal
    ,       SUM (e.sal) OVER ()                    AS comp_tot_sal
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    ;

Maybe you are looking for

  • Errors when saving to SMB mounts (a thorough examination)

    Several of the users I support have reported the following issue when trying to save files to the network from Photoshop. I have found several threads about this on both the Adobe forums and the Mac forums. However, in most of the threads the informa

  • How do I get Snow Leopard to display 256 color?

    I am attempting to run the applications Fallout and Fallout 2 on my 13" screen MacBook Pro, and each of these requires 8-bit color support. When I open the application, a normally colored small window appears for a couple of seconds, plays some music

  • I found the answer to my question where are the file, edit tools, etc menus

    == Issue == I have another kind of problem with Firefox == Description == file, tool, edit menus can be found by hitting the alt key == Firefox version == 3.6.3 == Operating system == Windows XP == User Agent == Mozilla/5.0 (Windows; U; Windows NT 5.

  • Keep exported image size in HTML as shown in PDF

    I have many inline formulas (imported from Word file via using mathtype) in PDF article made by ID. But when I export the articles as HTML, the images for formulas become much larger than shown in PDF version. How can i keep the exported images to th

  • Users on Linux system

    Hi, I need to modify the .bashrc files of Linux from Java code to add a directory to $PATH. My problem is that in Linux every user directory has a .bashrc file, to modify all the files from the code, I need to find out all the existing users of the s