简体   繁体   English

按字段拆分列并合并记录MS Access 2007

[英]Split columns by field and combine records MS Access 2007

I have the following Query where I am breaking up one column into different columns based on the field "Required." 我有以下查询,其中我根据字段“ Required”将一列分为不同的列。

SELECT 
Station, 
Line, 
[Tag Reference], 
FTN, 
IIF(Required = "TF", Required, "") AS [TF Required], 
IIF(Required = "TF", [Date Checked], "") AS [TF Date], 
IIF(Required = "TF", [User Checked], "") AS [TF User], 
IIF(Required = "ML", Required, "") AS [ML Required], 
IIF(Required = "ML", [Date Checked], "") AS [ML Date], 
IIF(Required = "ML", [User Checked], "") AS [ML User], 
Format

FROM [Tag Information]

ORDER BY 
Station, 
Line, 
[Tag Reference]

I am getting items where each record is its own line, but would like to group the records together. 我正在获取每个记录都是其各自行的项目,但想将记录分组在一起。

IE. IE浏览器 I am getting this table where the rows are split, but I would like to see values that are grouped by the Tag Reference. 我得到的表是行被拆分的地方,但是我想查看按标记引用分组的值。 (Like the second table) (就像第二张桌子一样)

Station Line    Tag Reference   FTN TF Required TF Date TF User ML Required ML Date ML User Format
Clearbrook  1   SCADA[30].0                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].0     TF                      
Clearbrook  1   SCADA[30].1                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].1     TF                      
Clearbrook  1   SCADA[30].10                    ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].2                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].4                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].4     TF  7/12/2006   WPB             
Clearbrook  1   SCADA[30].5     TF  7/12/2006   WPB             
Clearbrook  1   SCADA[30].5                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].6                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].8                 ML  7/12/2006   WPB 
Clearbrook  1   SCADA[30].8     TF  7/12/2006   WPB             
Clearbrook  1   SCADA[30].9     TF  7/12/2006   WPB             
Clearbrook  1   SCADA[30].9                 ML  7/12/2006   WPB 

I would like to see this table: 我想看这张桌子:

    Station Line    Tag Reference   FTN TF Required TF Date TF User ML Required ML Date ML User Format
    Clearbrook  1   SCADA[30].0     TF          ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].1     TF          ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].10                    ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].2                 ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].4     TF  7/12/2006   WPB ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].5     TF  7/12/2006   WPB ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].6                 ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].8     TF  7/12/2006   WPB ML  7/12/2006   WPB 
    Clearbrook  1   SCADA[30].9     TF  7/12/2006   WPB ML  7/12/2006   WPB 

Any Help would be great. 任何帮助都会很棒。 I am at a loss. 我很茫然。

You should be able to use a GROUP BY query to consolidate the results, something like the following: 您应该能够使用GROUP BY查询来合并结果,如下所示:

Say you have a table named [ThingStatus] with the data... 假设您有一个名为[ThingStatus]的表,其中包含数据...

ThingName  Status1  Status2
---------  -------  -------
foo        thing1          
foo                 thing2 

the you can consolidate the entries using the query... 您可以使用查询合并条目...

SELECT 
    ThingStatus.ThingName, 
    Max(ThingStatus.Status1) AS Status1, 
    Max(ThingStatus.Status2) AS Status2
FROM ThingStatus
GROUP BY ThingStatus.ThingName;

...which gives you ...这给你

ThingName  Status1  Status2
---------  -------  -------
foo        thing1   thing2 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM