Group By and JOIN within SQL Server (when dealing with multiple columns)

  • Maybe as below.  No directly usable data so I can't test it.  This code takes advantage of the fact that df1.host is known to be equal to df2.pc.

    SELECT df1.host, 
    df1.date,
    sum(df2.cap) AS cap,
    sum(df2.free) AS free,
    df1.purpose,
    df1.host AS pc
    FROM df1
    JOIN df2 ON
    df1.host = df2.pc
    GROUP BY df1.purpose, df1.host, df1.date

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply