Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

How do I save a “Count” SQL(server management studio 2008R2) query?

$
0
0

 

How do I save a “Count” SQL query?

First “Count” query;

 SELECT PrimaryKey,

 HostName,

 Operation,

 COUNT(*)as'Updated'

 FROM [Testdb].[dbo].[Audit]

 where Operationlike'u'

 GROUPBY PrimaryKey,

 HOSTNAME,

 Operation 

 orderby HostName

Result of the First “Count” query;

From this query we can see that “Hostname” PC091 performed 4 “u” “Operations” on “PrimaryKey” 70148

PrimaryKey HostName Operation Updated
70148 PC091 u 4
70156 PC091 u 4
70191 PC091 u 3
70202 PC093 u 4
70231 PC093 u 4
70296 PC093 u 4
70345 PC093 u 4
70401 PC095 u 4
70409 PC095 u 3
70460 PC095 u 4
70490 PC095 u 4
70498 PC095 u 3

I would like to perform a “Count” query on the above table to show how many “PrimaryKey” where updated by each “Hostname”

Expected results;

HostName Operation Updated
PC091 u 3
PC093 u 4
PC095 u 5

Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>