Access 2010 - 在一个“查询”字段中查询多个表列,以根据特定条件创建列表

时间:2014-04-16 23:41:04

标签: sql ms-access-2010

我有一个包含以下表格的查询:tblPosition, tblWorkArea, tblSkills

  • tblPositionID_Position, Position
  • tblWorkAreaID_WorkArea, WorkArea, Position
  • tblSkillsID_WorkArea,以及大约40种不同数字值的不同技能。

我想设置一个select查询,以便在给定以下参数的情况下生成表:WorkArea和Position。例如,工作区域是工程,位置是技术人员。生成的表应仅列出适用于这两个参数的那些技能(40个中)。 ID_WorkArea适用于WorkArea和Position的每个组合。所有ID_WorkArea都存储在tblSkills中以及所有技能。我想制作一个选择查询来选择给定ID_WorkArea的某些技能。

技能范围从0到30个数值。任何值为0的技能都意味着它不是必需的。

我对select查询的当前设置如下:

ID_WorkArea,WorkArea,Position,Skill1,skill2等.WorkArea和Position的标准是[Enter WorkArea]和[Enter Position]。每项技能的标准是< 0>。

问题是当我运行它时,至少有一个技能值为0的ID根本不返回数据记录。我希望看到剩下的技能,减去值为0的技能领域。

是否可以运行单个查询,根据输入的参数生成不同数量的字段?

SQL代码 -

SELECT 
   tblWorkArea.ID_LaborCore, tblWorkArea.[Labor Core], 
   tblWorkArea.Position, 
   tblSkills.[Reading Schematics], tblSkills.Wiring, 
   tblSkills.[Wire Type], tblSkills.[Terminal Types], 
   tblSkills.[NEMA Ratings], tblSkills.[UL 508], 
   tblSkills.[Attention to Detail], tblSkills.[Lifting 50lbs], 
   tblSkills.[Knowledge of Procedure], tblSkills.Crimper, 
   tblSkills.[Heat Gun], tblSkills.Screwdriver, tblSkills.Stripper, 
   tblSkills.[Impact Drill], tblSkills.[Radial Saw], 
   tblSkills.Multimeter, tblSkills.[Torque Screwdriver/Wrench], 
   tblSkills.[Tape Measure], tblSkills.Vacuum, 
   tblSkills.[Drill Press], tblSkills.[Jig Saw], 
   tblSkills.[Troubleshooting Components], tblSkills.[Problem Solving], 
   tblSkills.Organization, tblSkills.[Large Panel], 
   tblSkills.[Test Procedures], tblSkills.[Functional Testing], 
   tblSkills.[Writing Test Procedures], tblSkills.[Material Management], 
   tblSkills.[Set Meter Ability], tblSkills.[Tone Generator], 
   tblSkills.[Megger Testing], tblSkills.[Network Tracer], 
   tblSkills.Components, tblSkills.Fuses, 
   tblSkills.[Heat Shrink Color Codes], tblSkills.[Proper Lug or Crimping], 
   tblSkills.[Resistors Knowledge], tblSkills.Oscilloscopes, 
   tblSkills.Waveforms, tblSkills.[Voltage Separation], 
   tblSkills.[Skill x_Stapling]
FROM 
   (tblWorkArea 
INNER JOIN 
   tblPosition ON tblWorkArea.Position = tblPosition.Postion) 
LEFT JOIN 
   tblSkills ON tblWorkArea.ID_LaborCore = tblSkills.ID_LaborCore
WHERE 
   (((tblWorkArea.[Labor Core]) = [Enter labor core]) 
   AND ((tblWorkArea.Position) = [Enter Position]) 
   AND ((tblSkills.[Reading Schematics]) <> 0) 
   AND ((tblSkills.Wiring) <> 0) 
   AND ((tblSkills.[Wire Type]) <> 0) 
   AND ((tblSkills.[Terminal Types]) <> 0) AND ((tblSkills.[NEMA Ratings])<>0) AND ((tblSkills.[UL 508])<>0) AND ((tblSkills.[Attention to Detail])<>0) AND ((tblSkills.[Lifting 50lbs])<>0) AND ((tblSkills.[Knowledge of Procedure])<>0) AND ((tblSkills.Crimper)<>0) AND ((tblSkills.[Heat Gun])<>0) AND ((tblSkills.Screwdriver)<>0) AND ((tblSkills.Stripper)<>0) AND ((tblSkills.[Impact Drill])<>0) AND ((tblSkills.[Radial Saw])<>0) AND ((tblSkills.Multimeter)<>0) AND ((tblSkills.[Torque Screwdriver/Wrench])<>0) AND ((tblSkills.[Tape Measure])<>0) AND ((tblSkills.Vacuum)<>0) AND ((tblSkills.[Drill Press])<>0) AND ((tblSkills.[Jig Saw])<>0) AND ((tblSkills.[Troubleshooting Components])<>0) AND ((tblSkills.[Problem Solving])<>0) AND ((tblSkills.Organization)<>0) AND ((tblSkills.[Large Panel])<>0) AND ((tblSkills.[Test Procedures])<>0) AND ((tblSkills.[Functional Testing])<>0) AND ((tblSkills.[Writing Test Procedures])<>0) AND ((tblSkills.[Material Management])<>0) AND ((tblSkills.[Set Meter Ability])<>0) AND ((tblSkills.[Tone Generator])<>0) AND ((tblSkills.[Megger Testing])<>0) AND ((tblSkills.[Network Tracer])<>0) AND ((tblSkills.Components)<>0) AND ((tblSkills.Fuses)<>0) AND ((tblSkills.[Heat Shrink Color Codes])<>0) AND ((tblSkills.[Proper Lug or Crimping])<>0) AND ((tblSkills.[Resistors Knowledge])<>0) AND ((tblSkills.Oscilloscopes)<>0) AND ((tblSkills.Waveforms)<>0) AND ((tblSkills.[Voltage Separation])<>0) AND ((tblSkills.[Skill x_Stapling])<>0));

谢谢!

1 个答案:

答案 0 :(得分:0)

好的,好的。它实际上是你的where子句导致了这个。如果您需要单独处理每项技能,为了过滤查询和撤回人员,您将需要在where子句中将所有这些AND更改为OR。基本上,where子句说“只给我在所有列中只有零的人”

试试这个:

SELECT  tblWorkArea.ID_LaborCore ,
        tblWorkArea.[Labor Core] ,
        tblWorkArea.Position ,
        tblSkills.[Reading Schematics] ,
        tblSkills.Wiring ,
        tblSkills.[Wire Type] ,
        tblSkills.[Terminal Types] ,
        tblSkills.[NEMA Ratings] ,
        tblSkills.[UL 508] ,
        tblSkills.[Attention to Detail] ,
        tblSkills.[Lifting 50lbs] ,
        tblSkills.[Knowledge of Procedure] ,
        tblSkills.Crimper ,
        tblSkills.[Heat Gun] ,
        tblSkills.Screwdriver ,
        tblSkills.Stripper ,
        tblSkills.[Impact Drill] ,
        tblSkills.[Radial Saw] ,
        tblSkills.Multimeter ,
        tblSkills.[Torque Screwdriver/Wrench] ,
        tblSkills.[Tape Measure] ,
        tblSkills.Vacuum ,
        tblSkills.[Drill Press] ,
        tblSkills.[Jig Saw] ,
        tblSkills.[Troubleshooting Components] ,
        tblSkills.[Problem Solving] ,
        tblSkills.Organization ,
        tblSkills.[Large Panel] ,
        tblSkills.[Test Procedures] ,
        tblSkills.[Functional Testing] ,
        tblSkills.[Writing Test Procedures] ,
        tblSkills.[Material Management] ,
        tblSkills.[Set Meter Ability] ,
        tblSkills.[Tone Generator] ,
        tblSkills.[Megger Testing] ,
        tblSkills.[Network Tracer] ,
        tblSkills.Components ,
        tblSkills.Fuses ,
        tblSkills.[Heat Shrink Color Codes] ,
        tblSkills.[Proper Lug or Crimping] ,
        tblSkills.[Resistors Knowledge] ,
        tblSkills.Oscilloscopes ,
        tblSkills.Waveforms ,
        tblSkills.[Voltage Separation] ,
        tblSkills.[Skill x_Stapling]
FROM    ( tblWorkArea
          INNER JOIN tblPosition ON tblWorkArea.Position = tblPosition.Postion
        )
        INNER JOIN tblSkills ON tblWorkArea.ID_LaborCore = tblSkills.ID_LaborCore
WHERE   ( ( ( tblWorkArea.[Labor Core] ) = [Enter labor core] )
          AND ( ( tblWorkArea.Position ) = [Enter Position] )
          AND ( ( ( tblSkills.[Reading Schematics] ) <> 0 )
                OR ( ( tblSkills.Wiring ) <> 0 )
                OR ( ( tblSkills.[Wire Type] ) <> 0 )
                OR ( ( tblSkills.[Terminal Types] ) <> 0 )
                OR ( ( tblSkills.[NEMA Ratings] ) <> 0 )
                OR ( ( tblSkills.[UL 508] ) <> 0 )
                OR ( ( tblSkills.[Attention to Detail] ) <> 0 )
                OR ( ( tblSkills.[Lifting 50lbs] ) <> 0 )
                OR ( ( tblSkills.[Knowledge of Procedure] ) <> 0 )
                OR ( ( tblSkills.Crimper ) <> 0 )
                OR ( ( tblSkills.[Heat Gun] ) <> 0 )
                OR ( ( tblSkills.Screwdriver ) <> 0 )
                OR ( ( tblSkills.Stripper ) <> 0 )
                OR ( ( tblSkills.[Impact Drill] ) <> 0 )
                OR ( ( tblSkills.[Radial Saw] ) <> 0 )
                OR ( ( tblSkills.Multimeter ) <> 0 )
                OR ( ( tblSkills.[Torque Screwdriver/Wrench] ) <> 0 )
                OR ( ( tblSkills.[Tape Measure] ) <> 0 )
                OR ( ( tblSkills.Vacuum ) <> 0 )
                OR ( ( tblSkills.[Drill Press] ) <> 0 )
                OR ( ( tblSkills.[Jig Saw] ) <> 0 )
                OR ( ( tblSkills.[Troubleshooting Components] ) <> 0 )
                OR ( ( tblSkills.[Problem Solving] ) <> 0 )
                OR ( ( tblSkills.Organization ) <> 0 )
                OR ( ( tblSkills.[Large Panel] ) <> 0 )
                OR ( ( tblSkills.[Test Procedures] ) <> 0 )
                OR ( ( tblSkills.[Functional Testing] ) <> 0 )
                OR ( ( tblSkills.[Writing Test Procedures] ) <> 0 )
                OR ( ( tblSkills.[Material Management] ) <> 0 )
                OR ( ( tblSkills.[Set Meter Ability] ) <> 0 )
                OR ( ( tblSkills.[Tone Generator] ) <> 0 )
                OR ( ( tblSkills.[Megger Testing] ) <> 0 )
                OR ( ( tblSkills.[Network Tracer] ) <> 0 )
                OR ( ( tblSkills.Components ) <> 0 )
                OR ( ( tblSkills.Fuses ) <> 0 )
                OR ( ( tblSkills.[Heat Shrink Color Codes] ) <> 0 )
                OR ( ( tblSkills.[Proper Lug or Crimping] ) <> 0 )
                OR ( ( tblSkills.[Resistors Knowledge] ) <> 0 )
                OR ( ( tblSkills.Oscilloscopes ) <> 0 )
                OR ( ( tblSkills.Waveforms ) <> 0 )
                OR ( ( tblSkills.[Voltage Separation] ) <> 0 )
                OR ( ( tblSkills.[Skill x_Stapling] ) <> 0 )
              )
        )