SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to obtain Sum of count


How to obtain Sum of count

Author
Message
demonfox
demonfox
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2209 Visits: 1192
Steve Jones - SSC Editor (1/16/2013)
This kind of works, but I'm wondering if you've calculated something in this view already.

SELECT cid, COUNT(DISTINCT ccid)
FROM dbo.MyTable
GROUP BY cid



I think this should be fine ..If not please post the ddl's .I am unable to understand the problem..
this is how I tried , le me know it works for you..

CREATE TABLE #test
(
CID INT,
CCID CHAR(10),
CCOUNT INT
)

INSERT INTO #test
VALUES (2,'a',1),
(2,'b',1)
-- Edited this part
SELECT *,

(SELECT SUM(ccount) FROM(SELECT CCOUNT
FROM #test GROUP BY CID,CCOUNT)abc)CountTotal
FROM #test



~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search