Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

group a column and SUM A sales sum

trying to get a  sales sum based on 2 groupings
group and sum
I'm trying to get a sales sum  Column C
BASED ON a grouping IN  Column B

I keep repeating the values in Column B

SELECT   top 10000
      ,VAC_TOOL]
      ,[JAMONTH]
      ,SUM([sum])
   
  FROM [sflow].[dbo].[STC]

GROUP BY
     ,VAC_TOOL]
      ,[JAMONTH]
      ,[sum]
 

tHANKS
fordraiders
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
Answer_Me

Use Pivot Table.
Scott Pletcher

It looks like it's by VAC_TOOL also, therefore:

SELECT VAC_TOOL, JAMONTH, SUM(SALES)
FROM ...
GROUP BY VAC_TOOL, JAMONTH
Answer_Me

Use Pivort Table for Excel
For SQL Server assuming your table names is sales following query should do you job.
SELECT CALMONTH,SUM(sls_sum)
FROM SALES
GROUP BY CALMONTH
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Fordraiders

ASKER
Why is it i add another field the group then gets thrown off.


SELECT [sold_to], VAC_TOOL, JAMONTH, SUM(SALES)
FROM ...
GROUP BY [sold_to], VAC_TOOL, JAMONTH
Fordraiders

ASKER
nm i see why..
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
yo_bee

I am not seeing any filtering applied (no where clause

Select vac_tool,Jamonth, sum(sales)
From some table
Where field in('201611', '201605', etc....)
Group by vac_tool,jamonth
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Fordraiders

ASKER
Thanks all !!