Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag 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
User generated image
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
Avatar of Answer_Me
Answer_Me
Flag of India image

Use Pivot Table.
Avatar of Scott Pletcher
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
Avatar of 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
nm i see why..
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks all !!