简体   繁体   中英

Count Number of occurrences SQL

I'm trying to count the number of occurrences separate log messages appears per client

My table is in this structure

EventTime - Logmessage - HostName -  Client

This query gives me a number of logs for each client:

 SELECT Count([Log Message]) AS Count
  ,[Client]
 FROM [test1].[dbo].[logs_test]
 Group By Client

How would I go down into a lower level and get the number of times a log appears per client? The output I'm looking to achieve is something like the below

Log Message    Count  Client

NON ATTEMPT    12     TestClient

Appreciate any help

You will need to change what you are counting and add another level to your grouping...

 SELECT LogMessage
  , Count(EventTime) AS Count
  , Client
 FROM [test1].[dbo].[logs_test]
 Group By Client, LogMessage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM