Querying a table on it self MS SQL

I’m puzzeling a little with a SQL query / vTable i want to make. We have a table that contains computers (virtual and physical)

CluserName, ComputerName, CoreCount
N/A, BackOffice1, 2
cluster1, sqlServer, 4
cluster1, webserver, 2
cluser1, sqlServer2, 6
cluster2, adServer, 2
cluser2, adServer2, 4

I would not like to pull a vTable that would give me something like this:

Cluster: cluster1, 12 (this is a summation of the cores in the
sqlServer, 4
webserver, 2
sqlServer2, 6
Cluster: cluster2, 6
adServer, 2
adServer2, 4

So my two questions is:

1) is it stupid to do this via a vTable
2) If not is this an INNER JOIN or a nested query?


Source: sql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.