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
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Answer_MeCommented:
Use Pivot Table.
Scott PletcherSenior DBACommented:
It looks like it's by VAC_TOOL also, therefore:

SELECT VAC_TOOL, JAMONTH, SUM(SALES)
FROM ...
GROUP BY VAC_TOOL, JAMONTH
Answer_MeCommented:
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
5 Ways Acronis Skyrockets Your Data Protection

Risks to data security are risks to business continuity. Businesses need to know what these risks look like – and where they can turn for help.
Check our newest E-Book and learn how you can differentiate your data protection business with advanced cloud solutions Acronis delivers

FordraidersAuthor Commented:
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
FordraidersAuthor Commented:
nm i see why..
Scott PletcherSenior DBACommented:
Ah, if you don't want VAC_TOOL to be distinguished, drop it from the SELECT and the GROUP BY:

SELECT JAMONTH, SUM(SALES)
FROM [sflow].[dbo].[STC]
GROUP BY JAMONTH

If you want VAC_TOOL(s) listed, you'll have to limit the number, but you could use a counter to distinguish them all:

SELECT JAMONTH, SUM(SALES), MIN(VAC_TOOL) AS VAC_TOOL_FIRST, MAX(VAC_TOOL) AS VAC_TOOL_LAST, COUNT(DISTINCT VAC_TOOL) AS VAC_TOOL_COUNT
FROM [sflow].[dbo].[STC]
GROUP BY JAMONTH

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yo_beeDirector of Information TechnologyCommented:
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
FordraidersAuthor Commented:
Thanks all !!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.