views:

84

answers:

1

I am working on a one to many query for an assets database. Here is some sample data

Server Name        Application        Primary_User
Server1            SQL                DBA
Server1            Citrix             IT
Server1            Oracle             DBA
Server2            Sharepoint         Web
Server3            SQL                DBA
Server3            Sharepoint         Web
Server3            Norton             Security
Server3            IDS                Security

The desired output is one row per server with the server name, count of applications, and the Primary User that appears the most (not just the first, last, min, or max).

It would look like this

Server Name  Applications Primary_User
Server1            3      DBA
Server2            1      Web
Server3            4      Security

Is there a query or sub query that can accomplish this?
Just a note that this query will have to be executed in Excel.

Thanks in advance!

A: 

in T-SQL (MS SQL Server):

SELECT [Server Name], Count(*) AS Applications, Primary_User
FROM WHATEVER_THE_TABLE_IS_CALLED
GROUP BY [Server Name], Primary_User

I'm not sure what specific dialect of SQL you would be using, you might need to quote names differently.

Tao
OK, so I just realized you said this is to be executed in excel... By what mechanism?? Are you using an ODBC data source in Excel?
Tao