0

I have an SQL Server table Cascading with following structure:

+----+--------+----------------+           +----------------+-----------+  
| ID | NodeID | ActivationTime |           | ActivationTime | NodeCount |  
+----+--------+----------------+           +----------------+-----------+  
| 1  | 448    | 1              |           | 1              | 1         |  
| 2  | 195    | 2              |           | 2              | 3         |  
| 3  | 504    | 2              |           | 3              | 6         |  
| 4  | 609    | 2              |           | ...            | ...       |  
| 5  | 15     | 3              |           | ...            | ...       |  
| 6  | 31     | 3              |    =>     | ...            | ...       |  
| 7  | 56     | 3              |           | ...            | ...       |  
| 8  | 461    | 3              |           | ...            | ...       |  
| 9  | 585    | 3              |           | ...            | ...       |  
| 10 | 345    | 3              |           | ...            | ...       |  
| .. | ...    | ...            |           | ...            | ...       |  
+----+--------+----------------+           +----------------+-----------+

I need to calculate the number of times NodeID is appearing in the table with DISTINCT ActivationTime. For instance, 1 node at ActivationTime 1, 3 nodes at ActivationTime 2, 6 nodes at ActivationTime 3 and so on. The desired result is shown at the right side.

I tried the following unsuccessful query:

SELECT DISTINCT(ActivationTime) FROM CASCADING WHERE ActivationTIme IN
(SELECT DISTINCT(COUNT(ActivationTime)) AS NodeCount FROM CASCADING
GROUP BY ActivationTime)

3 Answers 3

2

Use COUNT(DISTINCT NodeID) and GROUP BY ActivationTime

SELECT ActivationTime, COUNT(DISTINCT NodeID) NumberOfID
FROM
  CASCADING
GROUP BY ActivationTime
Sign up to request clarification or add additional context in comments.

2 Comments

COUNT(DISTINCT NodeID)
Yes, I fixed it.
0

SELECT COUNT(NodeCount) AS Count, ActivationTime FROM CASCADING GROUP BY ActivationTime

Comments

0

It works for me by following:

select activationtime, count(*) from cascading group by activationtime;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.