SQL 查询:列出服务器最常使用的用户
我正在对资产数据库进行一对多查询。以下是一些示例数据
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
所需的输出是每台服务器一行,其中包含服务器名称、应用程序数量以及出现次数最多的主要用户(不仅仅是第一个、最后一个、最小或最大)。
它看起来像这样
Server Name Applications Primary_User
Server1 3 DBA
Server2 1 Web
Server3 4 Security
是否有查询或子查询可以完成此操作?
请注意,此查询必须在 Excel 中执行。
提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 T-SQL (MS SQL Server) 中:
我不确定您将使用哪种特定的 SQL 方言,您可能需要以不同的方式引用名称。
in T-SQL (MS SQL Server):
I'm not sure what specific dialect of SQL you would be using, you might need to quote names differently.