Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004
    Posts
    1

    Unanswered: Oracle newbie question.

    I am doing a small course on Oracle and have hit a brick wall with regard to one question.

    I have a few tables populated with data and I need to work out the sales of the 5 different outlets and then print the outlet to the screen that has had the most sales.

    The query I perform to get the totals is:

    BREAK ON branch_no SKIP 3
    COMPUTE SUM OF dam_cost ON branch_no
    SELECT member.branch_no, dam_cost
    FROM damage
    INNER JOIN damage_type
    ON damage.damage_code = damage_type.dam_type
    INNER JOIN breakdown
    ON damage.breakdown_id = breakdown.breakdown_id
    INNER JOIN member
    ON breakdown.member_id = member.member_no
    ORDER BY branch_no;

    which returns me a list of ALL branch numbers, their daily sales and the SUM, whereas I only need the branch number and the total (SUM) of their sales.

    I would of thought MAX() played a part but to be honest I am confused!!!

    Any help appreciated,
    Ryan

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Suppose your query is correct; modification you need might be this:
    Code:
    SELECT member.branch_no, SUM(dam_cost) sum_dam_cost
    FROM damage
    INNER JOIN damage_type
      ON damage.damage_code = damage_type.dam_type
    INNER JOIN breakdown
      ON damage.breakdown_id = breakdown.breakdown_id
    INNER JOIN member
      ON breakdown.member_id = member.member_no
    GROUP BY member.branch_no
    ORDER BY member.branch_no;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •