MS Access 中列名的字段值 SQL
Field Values to Column Names in MS Access SQL
如何转换:
Name Attributes
---- ----------
John Height
John Weight
John Age
Mary Shoe Size
Mary Hair Color
Mary Eye Color
to this:
Height Weight Age
名称和属性是访问 table 中的两个字段。我想根据名称字段中的值将属性值转换为字段名称。我正在使用 MS Access 2010。
我想我做了一些事情 select ???来自 table 其中名称="John"
在您的 table 中添加一个 'Value' 字段,这样它会像这样显示:
Name Attributes Value
---- ---------- -----
John Height 172
John Weight 87
John Age 25
Mary Shoe Size 9.5
Mary Hair Color Brown
Mary Eye Color Blue
您可以在 Access
中使用 'TRANSFORM' 和 'PIVOT'
TRANSFORM FIRST(Value)
SELECT Name FROM MyTable
GROUP BY Name
PIVOT Attributes
如何转换:
Name Attributes
---- ----------
John Height
John Weight
John Age
Mary Shoe Size
Mary Hair Color
Mary Eye Color
to this:
Height Weight Age
名称和属性是访问 table 中的两个字段。我想根据名称字段中的值将属性值转换为字段名称。我正在使用 MS Access 2010。
我想我做了一些事情 select ???来自 table 其中名称="John"
在您的 table 中添加一个 'Value' 字段,这样它会像这样显示:
Name Attributes Value ---- ---------- ----- John Height 172 John Weight 87 John Age 25 Mary Shoe Size 9.5 Mary Hair Color Brown Mary Eye Color Blue
您可以在 Access
中使用 'TRANSFORM' 和 'PIVOT'TRANSFORM FIRST(Value)
SELECT Name FROM MyTable
GROUP BY Name
PIVOT Attributes