Sumatory error

  • Hi guys, my question is the following: 
    How is the sumatory (sum(units_sold)) giving me the number of units and not the sumatory of all the units made by the publisher FCA? 
    Could you give me some advice on it?

    This is what I've done until now:

    SELECT TITLE, SUM(UNITS_SOLD)
    FROM BOOKS
    WHERE (TITLE,UNITS_SOLD)  IN(SELECT TITLE, UNITS_SOLD
    FROM BOOKS B, PUBLISHER P
    WHERE B.CODE_PUBLISHER=P.CODE_PUBLISHER AND P.NOME LIKE '%FCA%')
    GROUP BY TITLE;

  • You have a GROUP BY on Title. If you simply want a total of the sales of a specific Publisher defined in the WHERE clause, then drop the GROUP BY clause.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thank you! 🙂

  • joao.piti98 - Sunday, January 14, 2018 11:07 AM

    Hi guys, my question is the following: 
    How is the sumatory (sum(units_sold)) giving me the number of units and not the sumatory of all the units made by the publisher FCA? 
    Could you give me some advice on it?

    This is what I've done until now:

    SELECT TITLE, SUM(UNITS_SOLD)
    FROM BOOKS
    WHERE (TITLE,UNITS_SOLD)  IN(SELECT TITLE, UNITS_SOLD
    FROM BOOKS B, PUBLISHER P
    WHERE B.CODE_PUBLISHER=P.CODE_PUBLISHER AND P.NOME LIKE '%FCA%')
    GROUP BY TITLE;

    This doesn't look like MS SQL Server.  Are you using Oracle, as it looks an Oracle construct with the IN clause.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply