Results 1 to 7 of 7
  1. #1
    You My Nikka Nikos's Avatar
    Post Count
    3,314
    NBA Team
    San Antonio Spurs
    Anyone know ms-sql real well?

    Just curious?

    I am trying to do some query basics and am having trouble

  2. #2
    Metamorphism Morphgizmo's Avatar
    Post Count
    360
    NBA Team
    San Antonio Spurs
    Well, it's been about 3-4 years since I've written SQL, but I still have a decent text book lying around.

  3. #3
    needs a margarita
    Location
    San Antonio, baby!
    Post Count
    12,739
    NBA Team
    San Antonio Spurs
    Morph, is that your little girl? She's adorable!

    sorry for the hijack.

  4. #4
    You My Nikka Nikos's Avatar
    Post Count
    3,314
    NBA Team
    San Antonio Spurs

  5. #5
    Metamorphism Morphgizmo's Avatar
    Post Count
    360
    NBA Team
    San Antonio Spurs
    Nikos, what are you having trouble with?

    S y, yes. Thanks for noticing.

  6. #6
    You My Nikka Nikos's Avatar
    Post Count
    3,314
    NBA Team
    San Antonio Spurs
    The setup of my code is suppose to go something like this

    update groups g1
    set NumMems = (select count(...)
    from groups as g2, members as m
    where ...)

    groups is gid, gname, and Num Mems

    members table has member information and groupid # which is what I am trying to count. There are like 10 groups and each has a certain amount of people in each. I just want to be able to join the two tables, and insert the counts for each group into NumMems

    Im basically trying to make an update, linking the two tables, and inserting the group count for each group into nummems

  7. #7
    Metamorphism Morphgizmo's Avatar
    Post Count
    360
    NBA Team
    San Antonio Spurs
    Ok, this is what I came up with. I don't think it's exactly what you were looking for, but it may point you in the right direction.

    (Edit: I renamed your "Group" Table to "Cluster")

    Table #1: Cluster

    Code:
    Cluster_ID	Cluster_Name
    ---------------------------
    1	            Cluster Schmoe
    2	            Cluster Smith
    3	            Cluster Johnson
    Table #2: Member

    Code:
    Member_ID	Cluster_ID	Member_Name
    -------------------------------------------
    1	               1	          Joe Shmoe
    2	               1	          Jane Shmoe
    3	               2	          Joe Smith
    4	               2	           Jane Smith
    5	               3	           Joe Johnson
    6	               3	           Jane Johnson
    7	               2	           Chris Smith
    With the following query:

    Code:
    SELECT Cluster.Cluster_Name, Member.Cluster_ID, 
               COUNT(Member.Member_ID) AS NumMems
    FROM  Member INNER JOIN Cluster ON Cluster.Cluster_ID = Member.Cluster_ID
    GROUP BY Member.Cluster_ID, Cluster.Cluster_Name
    Gives an output table of:

    Code:
    Cluster_Name	Cluster_ID	NumMems
    ---------------------------------------
    Cluster Schmoe	 1	           2
    Cluster Smith	   2	             3
    Cluster Johnson	  3	            2
    Last edited by Morphgizmo; 10-14-2004 at 03:33 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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