1

我在为以下内容创建报告时遇到问题,正如您从包含的 csv 中看到的那样,查询正在生成重复项。我已经尝试了许多我能找到的 SQL 语句的变体,但没有任何运气。

主表:tblServers

Server ID,Server name,Hostname,Operating System,Admin Password,Attachments
1,"ESX","ESX",1,"**************","CS6.txt;WUG.docx"
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;Updates-WSUS.pdf"
3,"Deploy","deploy",3,"**************","WUG.docx"
5,"Newtest","newtest",2,"************",

二级表:tblSettings

ID,Server ID,Role,Feature,Application,Setting,sValue
1,1,1,,,1,"C:\inetpub"
2,1,1,,,6,"test.com"
3,1,1,,,4,"testuser"
4,1,1,,,5,"testpassword"
5,2,,7,,4,"root"
6,2,,7,,5,"pword"
7,2,,5,,6,"techtools.hopto.org"

第三张表:tblIP

ID,Sebnet,Last Octect,Description
1,"192.168.0",120,"DRAC"
1,"192.168.0",250,"Giga1"
2,"192.168.31",9,"VMWARE"
1,"192.168.31",250,"Giga2"

查询 - 结果

"Server ID","Server name","Hostname","Operating System","Admin Password","Attachments","Role","Feature","Application","Setting","sValue","IP","Description"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.0.250","Giga1"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.0.250","Giga1"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.0.250","Giga1"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.0.250","Giga1"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.0.120","DRAC"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.0.120","DRAC"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.0.120","DRAC"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.0.120","DRAC"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.31.250","Giga2"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.31.250","Giga2"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.31.250","Giga2"
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.31.250","Giga2"
2,"Media","media",2,"**************","**;**",,7,,4,"root","192.168.31.9","VMWARE"
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;**",,7,,5,"pword","192.168.31.9","VMWARE"
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;**",,5,,6,"**","192.168.31.9","VMWARE"

任何帮助将非常感激

编辑:

查询的 SQL

SELECT
  tblServers.[Server ID],
  tblServers.[Server name],
  tblServers.Hostname,
  tblServers.[Operating System],
  tblServers.[Admin Password],
  tblServers.Attachments,
  tblSettings.Role,
  tblSettings.Feature,
  tblSettings.Application,
  tblSettings.Setting,
  tblSettings.sValue,
  [tblIP]![Subnet] & "." & [tblIP]![Last Octect] AS IP,
  tblIP.Description
FROM (tblServers
  LEFT JOIN tblSettings ON tblServers.[Server ID] = tblSettings.[Server ID])
  INNER JOIN tblIP ON tblServers.[Server ID] = tblIP.[Server ID]
;
4

1 回答 1

0

Select Distinct是有用的地方。

您可以简单地将 Distinct Keyword 添加到您的查询中,如下所示,以获得没有重复的值。

SELECT Distinct tblServers.[Server ID], tblServers.[Server name], tblServers.Hostname, 
    tblServers.[Operating System], tblServers.[Admin Password], tblServers.Attachments,
    tblSettings.Role, tblSettings.Feature, tblSettings.Application, tblSettings.Setting,
    tblSettings.sValue, [tblIP]![Subnet] & "." & [tblIP]![Last Octect] AS IP,
    tblIP.Description
FROM (tblServers 
  LEFT JOIN tblSettings ON tblServers.[Server ID] = tblSettings.[Server ID]) 
  INNER JOIN tblIP ON tblServers.[Server ID] = tblIP.[Server ID];
于 2012-06-15T01:13:44.867 回答