Advertisement

05.30.2008 at 10:48AM PDT, ID: 23445423
[x]
Attachment Details

Group and Sum

Asked by allanau20 in MS SQL Server, SQL Server 2005

Hi Experts,

Need your help w/ a simple query.
This is for MS SQL 2005

Here's my SQL:

SELECT  SUBSTRING(FullName,1,4) Name, Section,
SUM(Cost) 'Cost'
 FROM tbl01
WHERE section = '1A1'
GROUP BY  SUBSTRING(FullName,1,4), Section, Cost

Here's the recordset:

Name  Section Cost
------- -------   -------
John   1A1     94
John   1A1     250
John   1A1     244756
Mark   1A1     24
Mark   1A1     562
Mark   1A1     14541
Mark   1A1     85796
Henry 1A1     8
Henry 1A1     44
Henry 1A1     125
Henry 1A1     2116
Henry 1A1     2270
Henry 1A1     4847
Henry 1A1     12234
Henry 1A1     244756

I was hoping to get it down to three records:
Name  Section Cost
------- ------- -------
John   1A1     ......
Mark   1A1     ......
Henry 1A1     ......

Any idea how to fix the sql?

TIA!Start Free Trial
 
Loading Advertisement...
 
[+][-]05.30.2008 at 10:52AM PDT, ID: 21679925

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 10:54AM PDT, ID: 21679945

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 10:54AM PDT, ID: 21679952

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005
Sign Up Now!
Solution Provided By: YZlat
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.30.2008 at 10:56AM PDT, ID: 21679970

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628