Click here to Skip to main content
15,915,975 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SID	NAME	COMPLETED_YEAR	COMPLETED_MONTH	COMPLETED_MONTH_NAME	TOTAL_COUNT
N060698	Paul D Ottaway	2016	5	           May	                     7
N060698	Paul D Ottaway	2016	6	          June	                    17
N060698	Paul D Ottaway	2016	7	          July	                    9
N060698	Paul D Ottaway	2016	8	         August	                   22
N060698	Paul Ottaway	2016	8	         August	                   3
N060698	Paul D Ottaway	2016	9	        September	           16
N060698	Paul Ottaway	2016	9	         September	           19
N060698	Paul D Ottaway	2016	10	       October	                   5
N060698	Paul Ottaway	2016	10	        October                    7

The above is the table input.

I want to fetch records where name="Paul D Ottaway" and totalcount in August= 22+3= 25 as one record.
OUTPUT I WANT as below where i have only fetched name ="Paul D Ottaway"
SID	NAME	COMPLETED_YEAR	COMPLETED_MONTH	COMPLETED_MONTH_NAME	TOTAL_COUNT
N060698	Paul D Ottaway	2016	5	                May	         7
N060698	Paul D Ottaway	2016	6	                June	        17
N060698	Paul D Ottaway	2016	7	                July	         9
N060698	Paul D Ottaway	2016	8	                August	         25
N060698	Paul D Ottaway	2016	9	                September	  35
N060698	Paul D Ottaway	2016	10	                October	          12


What I have tried:

I Tried to retrieve using count and sum.

Plese help me on this.
Posted
Updated 18-Nov-16 14:06pm
v2

Try:
SQL
SELECT [Name], SUM(Total_Count) AS TotalCount FROM MyTable 
WHERE SID = 'N060698' 
GROUP BY [Name], Complete_Month
 
Share this answer
 
Quote:
Write query to fetch name "paul D ottaway"
Did you see that your example can't use the name "paul D ottaway" to get the desired result as the second line for August is not this name?

The solution is likely to look like OriginalGriff's solution, which use SID.

If your data span on more than a year, you will need to add the COMPLETED_YEAR in the WHERE clause.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900