本文介绍了两列双排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按计算机和ipaddress分组,如何更改下面的查询.

I want to group by computer and ipaddress, how can change below query.

Computer1&192.168.1.3
计算机1 192.168.1.4

Computer1 192.168.1.3
Computer1 192.168.1.4


SELECT  SYS.Netbios_Name0 AS [计算机名],Count(*),
      
      [IP地址] = STUFF((SELECT','+ rasi.IP_Addresses0
        FROM dbo.v_RA_System_IPAddresses AS rasi
       在哪里rasi.ResourceID = SYS.ResourceID
        FOR XML PATH,TYPE).value(N'.[1]',N'nvarchar(max)'),1,1,'')
从v_R_SYSTEM SYS
完全加入SYS.ResourceID上的v_GS_COMPUTER_SYSTEM = v_GS_COMPUTER_SYSTEM.ResourceID
启用完整的JOIN v_GS_PC_BIOS SYS.ResourceID = v_GS_PC_BIOS.ResourceID
sys.Netbios_Name0就像"Compu%"一样
按SYS.Netbios_Name0,SYS.ResourceID分组


SELECT  SYS.Netbios_Name0 AS [Computer Name], Count(*),
       
       [IP Addresses] = STUFF((SELECT ',' + rasi.IP_Addresses0
         FROM dbo.v_RA_System_IPAddresses AS rasi
         WHERE rasi.ResourceID = SYS.ResourceID
         FOR XML PATH, TYPE).value(N'.[1]',N'nvarchar(max)'),1,1,'')
FROM v_R_SYSTEM SYS
Full JOIN  v_GS_COMPUTER_SYSTEM on SYS.ResourceID = v_GS_COMPUTER_SYSTEM.ResourceID
Full JOIN v_GS_PC_BIOS on  SYS.ResourceID = v_GS_PC_BIOS.ResourceID
where sys.Netbios_Name0 like 'Compu%'
Group By SYS.Netbios_Name0, SYS.ResourceID

[email protected]

[email protected]

推荐答案

您可能希望将table.column添加到您的Count(*)中,但是您的分组依据已正确设置为 SYS.Netbios_Name0,但是第一个中具有AS [Computer Name]行,因此不确定这是否是原因的一部分.也许简化 声明,直到获得分组依据".

You want to possibly add the table.column to your Count(*) but you have your Group By correctly set on SYS.Netbios_Name0, but you have AS [Computer Name] in the first line, so not sure if that is part of the cause. Maybe simplify the statement until you get the Group By working.

W3学校-SQL GROUP BY语句

W3 Schools - SQL GROUP BY Statement

SELECT Shippers.ShipperName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID
GROUP BY ShipperName


这篇关于两列双排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 20:21