group a column and SUM A sales sum

Fordraiders
Fordraiders used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use Pivot Table.
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014

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

SELECT VAC_TOOL, JAMONTH, SUM(SALES)
FROM ...
GROUP BY VAC_TOOL, JAMONTH
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
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

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

Author

Commented:
nm i see why..
Senior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
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
yo_beeDirector of Information Technology

Commented:
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

Author

Commented:
Thanks all !!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial