Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having a table

CSS
cid in_rid  in_rc rid   rcom       date             mid
1   104     0     106     0       2012-11-07      108
2   103     0     106     0       2012-11-07      108
3   102     0     106     0       2012-11-07      108
4   101     0     106     0       2012-11-07      108
5   104     1     107    100      2012-11-07      109
6   103     2     107    100      2012-11-07      109
7   102     3     107    100      2012-11-07      109
8   101     4     107    100      2012-11-07      109
9   105     1     106    100      2012-11-07      110
10  102     2     106    100      2012-11-07      110
11  101     3     106    100      2012-11-07      110
12  101     1     107    100      2012-11-07      111
NULL    NULL    NULL    NULL    NULL    NULL    NULL



i want to run a query to get total rcom with no repeatation of mid

like on rid=107 i want 100+100 but its showing 400+100

SQL
my query is select sum(select distinct(mem_id),rcom from referal_commission where rid=107) from referal_commission

but i want sum of rcom
can someone plzz help
Posted
Updated 7-Nov-12 2:29am
v3
Comments
MT_ 7-Nov-12 8:27am    
There is inconsistencies in column names used in table and in query. Plus there are 5 records with rid=107. !!Please clear it a little and then someone can help.

Since your table column and query has few mismatch
I think use of distinct with group by is not required..

I have created a test query for your requirement in sort using 2 columns on basis of your requirement

"i want to run a query to get total rcom with no repeatation of mid"

Like this:
SQL
create table #temp(
rcom int,
mid int
)
insert into #temp(rcom,mid)values(0,108)
insert into #temp(rcom,mid)values(0,108)
insert into #temp(rcom,mid)values(100,109)
insert into #temp(rcom,mid)values(100,109)
insert into #temp(rcom,mid)values(100,110)
insert into #temp(rcom,mid)values(100,110)

select * from #temp

select SUM(rcom) as sum_rcom,mid from #temp group by mid


and Output is:

sum_rcom mid
0 108
400 109
400 110

Is this helpful..?
 
Share this answer
 
v2
Comments
Miss Maheshwari 7-Nov-12 8:47am    
no there are some duplicate entry i want
0 108
100 109
100 110
but again i want total/sum of these rcom like 200
SoumenBanerjee 7-Nov-12 13:22pm    
so can you please explain "some duplicate entry"
Have you try to apply Group by on rid, Mid column.
 
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