Anyone really good with queries?? :-)

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Anyone really good with queries?? :-)

    Given this database structure:

    GroupNumber GN End Range GroupName CustServInd
    7404 Don and Deb Lawyer A
    7405 Don and Deb Lawyer A
    7406 Don and Deb Lawyer A
    8683 Central Hardware Service A
    8684 Central Hardware Service A
    7616 Chemical Company HQ A
    9528 Wild Workout Center A
    0407 Wild Workout Center A
    8219 Wood Mill A
    8764 Don and Deb Lawyer A


    TheGN End Range field is to be populated with the maximum GroupNumber for a
    group, where a group is a unique GroupNumber and GroupName combo, AND THE
    GroupNumber's are in SEQUENCE. The Group Number End Range is only to be
    filled when there is more than 1 GroupNumber for a group. Thus, when the
    module is complete, the above record set should look like this:

    GroupNumber GN End Range GroupName CustServInd
    7404 7406 Don and Deb Lawyer A
    8683 8684 Central Hardware Service A
    7616 Chemical Company HQ A
    9528 Wild Workout Center A
    0407 Wild Workout Center A
    8219 Wood Mill A
    8764 Don and Deb Lawyer A

    The query I have below fills in Group Number End Range for Don and Deb
    Lawyer as 8764, but this is incorrect, as it is not in sequence. Another
    example would be Wild Workout Center. My query groups them as one, with an
    end range of 0407. but they should be treated as separate groups, since the
    numbers are not in sequence.

    SELECT Min([GroupNumber]) AS MinGroupNumber,
    IIf(Max([GroupNumber])>Min([GroupNumber]),Max([GroupNumber]),Null) AS
    MaxGroupNumber, GroupName, CustSvcInd
    FROM tblGroups
    GROUP BY CustSvcInd, GroupName
    ORDER BY CustSvcInd, Min(Groups.GroupNumber);

    Hopefully this all makes sense! I really need to take an sql class, I know
    bits and pieces but that's it...

    MikeD. Guest

  2. Similar Questions and Discussions

    1. Xcart no good, support no good, need good shopping cart!!!
      I need a good quality php shopping cart to port to my site, allowing software downloads and book sales. Integrating ease is really important and...
  3. #2

    Default Re: Anyone really good with queries?? :-)

    Having only seen what you posted, and not knowing what the relationship is
    between GroupNumber and GroupName, this hints of a hosed up data model. What
    are you trying to do, exactly? Why would you have multiple groun numbers for
    the same group name? It looks like GrouNumber may be a primary key, but is
    GroupName a foreign key value of some kind, or is it unrelated to any other
    entity?

    Phil

    paross1 Guest

  4. #3

    Default Re: Anyone really good with queries?? :-)

    I think it IS a hosed up data model, but I don't have any say over it... It is
    data that is stored in some old mainframe program, I really don't even
    understand the data. They just want to know when a Group Name appears multiple
    times, and what the lowest and highest number is.

    It comes to me as an excel spreadsheet, it's not a database with any
    relationships or anything like that.

    Thanks!


    MikeD. Guest

  5. #4

    Default Re: Anyone really good with queries?? :-)

    Select Max(GroupNumber) as maxnumber, Min(GroupNumber) As minnumber, GroupName
    From myTable
    Where 0=0
    Having Count(GroupName) > 1
    Group By GroupName

    Not sure if you need the where clause of zero equals zero as I'm unable to
    test now, but it will not hurt anyway.

    Ken

    The ScareCrow Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139