sql query- help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • desi90

    #1

    sql query- help!

    Hi,
    I have a table with the following data

    city_id issue_id region
    c1 i1 South
    c2 i1 South
    c3 i2 South
    c4 i3 South
    c5 i1 North
    c6 i4 North
    c7 i5 North
    c8 i1 East
    c9 i1 West
    c10 i3 West

    I am trying to create a report which list issues by region (South,
    North etc)
    This is what I would like to get in report
    issue_id count region
    i1 2 South
    i1 1 North
    i1 1 East
    i1 1 West
    i2 1 South
    i3 1 South
    i3 1 West

    This report is counting number of times the issue was encountered in
    the regions.
    How do I wrote sql query to prodice this data from the table

    Any help /ideas??

  • David

    #2
    Re: sql query- help!

    Assuming that your table is named Table_1, the following SQL syntax
    would do the trick:

    SELECT Table1.issue_id , Count(Table1.ci ty_id) AS CountOfcity_id,
    Table1.region
    FROM Table1
    GROUP BY Table1.issue_id , Table1.region
    ORDER BY Table1.issue_id , Count(Table1.ci ty_id) DESC;

    The fastest way to get this type of data is to use create a query of
    the table and choose Totals under View in the query window.

    Hope this helps.
    David Hodgkins, MCSD, MCDBA, MCSE
    dhodgkins@jstar software.com


    Comment

    Working...