Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    28

    Unanswered: How to consolidate the count?

    Reg code Cntry code Area code Count
    -------- ---------- --------- ------
    AF AO CAB 15
    AF AO LAD 20
    AF BF OUA 23
    AF BI BJM 11
    AF BW GBE 72
    AF CD FIH 30
    AF CD MNB 8

    I need the result like this

    Reg code cntry code Total

    AF AO 35
    AF BF 23
    AF BI 11
    AF Bw 72
    AF CD 38

    consolidated total of area code 15+20 = 35, 30 + 8 = 38

    table structures(two tables I am using)

    create temp table country (ccode char(5),
    acode char(4), rcode char(4));

    create temp table report(count char(5),acode char(5));

    how to write the sql?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: How to consolidate the count?

    This is a simple sum and group by:

    select c.rcode, c.ccode, sum(t.count)
    from country c, temp t
    where c.acode = t.acode
    group by c.rcode, c.ccode;

    BTW, why is column count declared as char(5)???

Posting Permissions

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