15,668,923 members
See more:
I have the following query now i need the sum of the count(*) values how can i do so

SQL
```select a.col1 , count(*) count_1  , sum(count_1)
from table1 a join table2 on a.id = b.id```
Posted
Updated 8-Aug-13 2:36am
v3
Maciej Los 8-Aug-13 8:36am
Please, post example data and expected output.

## Solution 2

I'm not sure what you want to achieve, but have a look at below example:

SQL
```SELECT F1, COUNT(F1) AS CountOfF1, SUM(F2) SumOfF2
FROM (
SELECT 1 AS F1, 2 AS F2
UNION ALL SELECT 1, 5
UNION ALL SELECT 1, 3
UNION ALL SELECT 1, 4
UNION ALL SELECT 2, 12
UNION ALL SELECT 2, 5
UNION ALL SELECT 2, 5
UNION ALL SELECT 2, 15
) AS T
GROUP BY F1

SELECT COUNT(F1) AS DistinctF1Fields, SUM(Q.CountOfF1) AS SumOfCountOfF1
FROM (
SELECT T.F1, COUNT(T.F1) AS CountOfF1, SUM(T.F2) SumOfF2
FROM (
SELECT 1 AS F1, 2 AS F2
UNION ALL SELECT 1, 5
UNION ALL SELECT 1, 3
UNION ALL SELECT 1, 4
UNION ALL SELECT 2, 12
UNION ALL SELECT 2, 5
UNION ALL SELECT 2, 5
UNION ALL SELECT 2, 15
) AS T
GROUP BY T.F1
) AS Q```

Result of 1. query:
```1	4	14
2	4	37```

Result of 2. query:
`2	8`

[no name] 8-Aug-13 9:50am
+5 from me.
Maciej Los 8-Aug-13 16:01pm
Thank you, sisir patro ;)
[no name] 9-Aug-13 3:21am
Yw
gvprabu 8-Aug-13 11:09am
Nice Example my 5+ :-)
Maciej Los 8-Aug-13 16:01pm
Thank you, Gopal ;)

## Solution 1

hi lalitkr

try this

SQL
```select  count(*) count_1
from table1 a join table2 on a.id = b.id```

Maciej Los 8-Aug-13 8:42am
lalitkr 8-Aug-13 12:29pm
Well my table is like this
id Col1 col2
1 2 6
2 3 6
3 1 6

now i want the result for the col2 as sum(col1) values and this will be displayed in the col2

so for this i used the query as

select xx.id , xx.col1 , xx.sum(col1) col2 from
( select a.id , cout(*) col1 from
table1 a join table2 b on a.id = b.id ) xx

on doing so i m getting repeating sum for the col1 now i want the sum in first row and for rest of coloumn
it resturn null value