| Author |
Topic |
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 00:54:57
|
| hi guys,I have got something like this,A S DBi Ar 23Bi Ar 12As Ar 52As Ar 11Ap Jo 24I Have 3 columns. First 2 columns are Text and the third one is Number. I need to see if any duplicate values are there in first 2 columns. If so then i need to add the values of 3 columns and make it one. So the output should look like this,A S DBi Ar 35As Ar 63Ap Jo 24 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 00:57:56
|
[code]selet A, S, D = sum(D)from yourtablegroup by A, S[/code] KH |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:08:12
|
| hey it says, " You tried to execute a query that does not include the specified expression ' D= sum(D)' as part of an aggregate function". What should i do? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 01:16:39
|
[code]declare @table table( A char(2), S char(2), D int)insert into @tableselect 'Bi', 'Ar', 23 union allselect 'Bi', 'Ar', 12 union allselect 'As', 'Ar', 52 union allselect 'As', 'Ar', 11 union allselect 'Ap', 'Jo', 24select A, S, D = sum(D)from @tablegroup by A, S/*A S D ---- ---- ----------- As Ar 63Bi Ar 35Ap Jo 24*/[/code]Please post your actual query. KH |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:24:50
|
| i cant use this method because i have 1060 entries. is there someother to do? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 01:28:10
|
the declare @table table is just for demonstrate the working of the queryJust change the table name, column name to your actualselect A, S, D = sum(D)from youractualtablenamegroup by A, S KH |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:35:49
|
| ya man i did that, but its still giving the same problem. this is the query i am trying to run,SELECT FirseName, LastName, Salary = sum(Salary)FROM [Employees]GROUP BY FirseName, LastName; |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 01:38:49
|
the query looks perfectly fine to me. Please post the exact error message KH |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:46:58
|
| it says, " You tried to execute a query that does not include the specified expression 'Salary= sum(Salary)' as part of an aggregate function". |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:53:35
|
| this is how my database looks and its a MS Access Database.FirstName LastName SalaryJack Wilson 2312Jack Wilson 3432Rey M 5615Rey M 45768David Reinjal 3211 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 01:55:53
|
I have no idea why you would get that error. What is the version of SQL Server ?create table [Employees]( FirseName char(2), LastName char(2), Salary int)insert into [Employees]select 'Bi', 'Ar', 23 union allselect 'Bi', 'Ar', 12 union allselect 'As', 'Ar', 52 union allselect 'As', 'Ar', 11 union allselect 'Ap', 'Jo', 24SELECT FirseName, LastName, Salary = sum(Salary)FROM [Employees]GROUP BY FirseName, LastName/*FirseName LastName Salary --------- -------- ----------- As Ar 63Bi Ar 35Ap Jo 24*/drop table [Employees] KH |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 01:58:55
|
| its not SQL, its MS Access DB. |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-22 : 02:00:16
|
| [code]SELECT FirseName, LastName, sum(Salary) as SalFROM EmployeesGROUP BY FirseName, LastName[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2007-03-22 : 02:10:36
|
| thnx harsh. its worked. sorry khtan i dint knew where to post. thnx anyway for ur replies and ur efforts. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-22 : 02:37:19
|
sorry MS Access is totally alien to me  KH |
 |
|
|
|