Ms access Access 2016交叉表/转换

Ms access Access 2016交叉表/转换,ms-access,transform,crosstab,Ms Access,Transform,Crosstab,我有一张桌子,我需要在水平模式下变换它 | id | Number | Name | |------|------------|--------| | 3695 | 0445458225 | Name1 | | 3695 | 0445458228 | Name2 | | 3695 | 0445458553 | Name3 | | 3695 | 0445458560 | Name4 | | 3695 | 0445458551 | Name5 | | 3695 | 0445

我有一张桌子,我需要在水平模式下变换它

| id   | Number     | Name   |
|------|------------|--------|
| 3695 | 0445458225 | Name1  |
| 3695 | 0445458228 | Name2  |
| 3695 | 0445458553 | Name3  |
| 3695 | 0445458560 | Name4  |
| 3695 | 0445458551 | Name5  |
| 3695 | 0445458561 | Name7  |
| 3695 | 0445458522 | Name8  |
| 3695 | 0445458543 | Name9  |
| 3696 | 0445458226 | Name10 |
| 3696 | 0445458540 | Name11 |
| 3696 | 0445458543 | Name12 |
| 3696 | 0445923962 | Name13 |
| 3696 | 0500266382 | Name14 |
| 3697 | 0445923962 | Name15 |
| 3697 | 0445458226 | Name16 |
| 3697 | 0500266382 | Name17 |
| 3697 | 0445458564 | Name18 |
我得到的信息如下:

| id    | Name1     | Name2     | Name3 | Name4    | Name5      | Name6 | Name7 | Name8 | Name9    | Name10 | Name11    | Name12   | Name13   |  
|------ |-----------|---------- |-------|----------|----------- |-------|-------|-------|----------|--------|---------- |----------|----------|  
| 3695  | 445458553 | 44518551  |       | 44548560 |            |       |       |       | 44548228 |        | 44548543  |          | 44548225 |  
| 3696  |           |           |       |          | 445923962  |       |       |       |          |        | 44548543  | 44548226 |          |  
| 3694  |           |           |       |          | 445923962  |       |       |       |          |        | 44548543  | 44548226 |          |
但我需要的是:

| id   | Member1   | Member2  | Member3  | Member4  | Member5  | Member6  | Member7 | Member8 | Member9 | Member10 | member11 | Name12 | Name13 |  
|------|-----------|----------|----------|----------|----------|----------|---------|---------|---------|----------|----------|--------|--------|  
| 3695 | 445458553 | 44518551 | 44548560 | 44548228 | 44548543 | 44548225 |         |         |         |          |          |        |        |  
| 3696 | 445923962 | 44548543 | 44548226 |          |          |          |         |         |         |          |          |        |        |  
| 3694 | 445923962 | 44548543 | 44548226 |          |          |          |         |         |         |          |          |        |        |
所以没有空单元格,列应该命名为,因为最后一个表也是原始id,数字和名称是不同的 每次查询运行时(不同的组id)

以下是我的SQL代码:

将平均值(Nick_agents.Number)转换为第一个数字
选择Nick_agents.id
Nick_的经纪人
由Nick_agents.id组成的组
PIVOT Nick_agents.Name;

Access有一个内置的交叉表查询向导,可以为您执行此操作

On the Create tab, in the Queries group, click Query Wizard.
The Queries group in the Access ribbon displays two options: Query Wizard and Query Design

在您的示例中,您的数据完全不同。在第一个示例中,将Name1、Name2、Name3作为字段名,在第二个示例中,将Member1、Member2、Member3作为字段名。假设这是您的实际数据

id  Number  Name
3697    445923962   Member1
3696    445923962   Member1
3695    445458553   Member1
3696    445458543   Member2
3697    445458543   Member2
3695    445458543   Member2
3695    445458551   Member2
3695    445458560   Member3
3696    445458226   Member3
3697    445458226   Member3
然后,这是您的SQL

TRANSFORM First(Table1.[Number]) AS FirstOfNumber
SELECT Table1.[id], First(Table1.[Number]) AS [Total Of Number]
FROM Table1
GROUP BY Table1.[id]
PIVOT Table1.[Name];
这是设计视图

当您运行SQL时,您会得到这样的结果


有意义吗?

我的SQL代码已经是一个交叉表查询(至少access这么说),所以没有帮助:-)你能发布你的实际数据吗?我可以将其复制/粘贴到表格中,并测试一些想法。我没有时间做数据输入练习。我添加了表格数据。我只是更新了原始答案。添加了一些图片、评论等。希望现在能有意义。嗨,谢谢。我想我没有正确地解释我的问题:-(.首先,我的表数据包含数字和名称,因此名为member1、2等的表将不起作用,因为一个名称可以在一个组中显示member1,而在另一个组中显示member2。因此,如果可以将该查询显示为SQL图片,但名称已足够,我可以尝试以其他方式重命名列。如果无法将其显示为我的上一张图片显示,是否可以将列重命名为上一张图片中的列?请将图像替换为文本,与表数据相同!格式为!如果尚未完成,请读取!
If you choose a Date/Time field for column headings, the next page of the wizard asks you to specify the interval to use to group the dates. You can specify Year, Quarter, Month, Date, or Date/Time. If you do not choose a Date/Time field for column headings, the wizard skips this page.

On the next page, choose a field and a function to use to calculate summary values. The data type of the field that you select determines which functions are available.

On the same page, select or clear the Yes, include row sums check box to include or exclude row sums.

If you include row sums, the crosstab query has an additional row heading that uses the same field and function as the field value. Including a row sum inserts an additional column that summarizes the remaining columns. For example, if your crosstab query calculates average age by location and gender (with gender column headings), the additional column calculates the average age by location, across all genders.

For this example, select ID in the Fields box and Count in the Functions box in order to have Access count the number of products in each intersection of supplier and category. Leave the Yes, include row sums check box selected. Access will create a column that totals the number of products from each supplier. Click Next to continue.
Select a field and function to calculate on the Crosstab query wizard.
On the last page of the wizard, type a name for your query and then specify whether you want to view the results or modify the query design.

You can change the function that is used to produce row sums by editing the crosstab query in Design view.

If you've walked through this example using the Products table from the Northwind database, the crosstab query displays the list of supplier names as rows, the product category names as columns, and a count of the number of products in each intersection.
id  Number  Name
3697    445923962   Member1
3696    445923962   Member1
3695    445458553   Member1
3696    445458543   Member2
3697    445458543   Member2
3695    445458543   Member2
3695    445458551   Member2
3695    445458560   Member3
3696    445458226   Member3
3697    445458226   Member3
TRANSFORM First(Table1.[Number]) AS FirstOfNumber
SELECT Table1.[id], First(Table1.[Number]) AS [Total Of Number]
FROM Table1
GROUP BY Table1.[id]
PIVOT Table1.[Name];