You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MS Access中基于特定属性对创建目标结构新表

在MS Access中构建以颜色为核心的花卉属性表

你可以通过交叉查询(Crosstab Query)或者自连接+聚合函数的方式实现需求,以下是具体操作方案:

方法一:交叉查询(推荐)

交叉查询能直接实现行转列,适配你需要的表结构:

  1. 打开MS Access,新建一个查询
  2. 切换到SQL视图,输入以下代码:
TRANSFORM First(t.Value) AS Value
SELECT t.Flowerno, 
       First(IIF(t.Attribute='shape', t.Value, Null)) AS shape,
       First(IIF(t.Attribute='fragrance', t.Value, Null)) AS fragrance
FROM YourTableName AS t
WHERE t.Attribute IN ('color', 'shape', 'fragrance')
GROUP BY t.Flowerno
PIVOT t.Attribute;
  • 将YourTableName替换为你实际使用的表名
  • 该查询会把color作为列名,同时提取对应花卉的shape和fragrance属性值

方法二:自连接查询

如果交叉查询不符合使用习惯,也可以用自连接的方式实现:

SELECT 
    c.Flowerno,
    c.Value AS color,
    s.Value AS shape,
    f.Value AS fragrance
FROM 
    (YourTableName AS c
INNER JOIN YourTableName AS s 
    ON c.Flowerno = s.Flowerno AND s.Attribute = 'shape')
INNER JOIN YourTableName AS f 
    ON c.Flowerno = f.Flowerno AND f.Attribute = 'fragrance'
WHERE c.Attribute = 'color';
  • 同样替换YourTableName为实际表名
  • 这个语句通过将表自连接三次,分别匹配color、shape、fragrance属性,最终合并成一行展示

将查询结果保存为新表

执行任意一种查询后,右键点击查询结果,选择保存为表,输入新表名称即可完成创建。

内容的提问来源于stack exchange,提问作者Mimi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 08:45:29