创建一个' x' ' y'柱

时间:2016-02-17 15:30:18

标签: sql ms-access

我正在试图弄清楚如何创建一个列,表明这是' x' ' y'项目。那么,我有的是下表:

Drawer ID   Drawer Name     Size            Qty     MaterialSchedule    PurchaseOrder   
253         5 Piece Drawer  15 1/2x3x20     4       19mm Tandem         DWR_TEST_001
254         5 Piece Drawer  15 1/2x3x20     4       19mm Tandem         DWR_TEST_001
255         5 Piece Drawer  15 1/2x3x20     4       19mm Tandem         DWR_TEST_001
256         5 Piece Drawer  15 1/2x3x20     4       19mm Tandem         DWR_TEST_001
257         5 Piece Drawer  17 1/2x3x20     4       19mm Tandem         DWR_TEST_001
261         5 Piece Drawer  17 1/2x3x20     4       19mm Tandem         DWR_TEST_001
265         5 Piece Drawer  17 1/2x3x20     4       19mm Tandem         DWR_TEST_001
269         5 Piece Drawer  17 1/2x3x20     4       19mm Tandem         DWR_TEST_001
260         5 Piece Drawer  17 1/2x6x20     4       19mm Tandem         DWR_TEST_001
264         5 Piece Drawer  17 1/2x6x20     4       19mm Tandem         DWR_TEST_001
268         5 Piece Drawer  17 1/2x6x20     4       19mm Tandem         DWR_TEST_001
272         5 Piece Drawer  17 1/2x6x20     4       19mm Tandem         DWR_TEST_001
248         5 Piece Drawer  26 1/2x3x20     5       19mm Tandem         DWR_TEST_001
249         5 Piece Drawer  26 1/2x3x20     5       19mm Tandem         DWR_TEST_001
250         5 Piece Drawer  26 1/2x3x20     5       19mm Tandem         DWR_TEST_001
251         5 Piece Drawer  26 1/2x3x20     5       19mm Tandem         DWR_TEST_001
252         5 Piece Drawer  26 1/2x3x20     5       19mm Tandem         DWR_TEST_001
258         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
259         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
262         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
263         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
266         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
267         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
270         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001
271         5 Piece Drawer  17 1/2x4x20     8       19mm Tandem         DWR_TEST_001

我需要做的是' x'柱。基本上,如果你看第一行,数量是4,我需要它有一个说1的列,第二行需要有一个值2,所以数据看起来像这样:

Drawer ID   Drawer Name     Size            Index   Qty     MaterialSchedule    PurchaseOrder   
253         5 Piece Drawer  15 1/2x3x20     1       4       19mm Tandem         DWR_TEST_001
254         5 Piece Drawer  15 1/2x3x20     2       4       19mm Tandem         DWR_TEST_001
255         5 Piece Drawer  15 1/2x3x20     3       4       19mm Tandem         DWR_TEST_001
256         5 Piece Drawer  15 1/2x3x20     4       4       19mm Tandem         DWR_TEST_001
257         5 Piece Drawer  17 1/2x3x20     1       4       19mm Tandem         DWR_TEST_001
261         5 Piece Drawer  17 1/2x3x20     2       4       19mm Tandem         DWR_TEST_001
265         5 Piece Drawer  17 1/2x3x20     3       4       19mm Tandem         DWR_TEST_001
269         5 Piece Drawer  17 1/2x3x20     4       4       19mm Tandem         DWR_TEST_001
260         5 Piece Drawer  17 1/2x6x20     1       4       19mm Tandem         DWR_TEST_001
264         5 Piece Drawer  17 1/2x6x20     2       4       19mm Tandem         DWR_TEST_001
268         5 Piece Drawer  17 1/2x6x20     3       4       19mm Tandem         DWR_TEST_001
272         5 Piece Drawer  17 1/2x6x20     4       4       19mm Tandem         DWR_TEST_001
248         5 Piece Drawer  26 1/2x3x20     1       5       19mm Tandem         DWR_TEST_001
249         5 Piece Drawer  26 1/2x3x20     2       5       19mm Tandem         DWR_TEST_001
250         5 Piece Drawer  26 1/2x3x20     3       5       19mm Tandem         DWR_TEST_001
251         5 Piece Drawer  26 1/2x3x20     4       5       19mm Tandem         DWR_TEST_001
252         5 Piece Drawer  26 1/2x3x20     5       5       19mm Tandem         DWR_TEST_001
258         5 Piece Drawer  17 1/2x4x20     1       8       19mm Tandem         DWR_TEST_001
259         5 Piece Drawer  17 1/2x4x20     2       8       19mm Tandem         DWR_TEST_001
262         5 Piece Drawer  17 1/2x4x20     3       8       19mm Tandem         DWR_TEST_001
263         5 Piece Drawer  17 1/2x4x20     4       8       19mm Tandem         DWR_TEST_001
266         5 Piece Drawer  17 1/2x4x20     5       8       19mm Tandem         DWR_TEST_001
267         5 Piece Drawer  17 1/2x4x20     6       8       19mm Tandem         DWR_TEST_001
270         5 Piece Drawer  17 1/2x4x20     7       8       19mm Tandem         DWR_TEST_001
271         5 Piece Drawer  17 1/2x4x20     8       8       19mm Tandem         DWR_TEST_001

我已经谷歌搜索了一段时间,但我不确定我能做到这一点。首先创建表的SQL是:

Select Drawers.[Drawer ID], Drawers.[Drawer Name], Trim(Drawers.[Width String]) + 'x' + Trim(Drawers.[Height String]) + 'x' + Trim(Drawers.[Depth String]) As [Size], DrawerCounts.Qty, Drawers.MaterialSchedule, [Job Info].PurchaseOrder
From (((Drawers Inner Join
DrawerCounts On Drawers.[Drawer Name] = DrawerCounts.[Drawer Name] And Drawers.Width = DrawerCounts.Width And Drawers.Height = DrawerCounts.Height And Drawers.Depth = DrawerCounts.Depth) Inner Join
Cabinets On Drawers.[Cabinet ID] = Cabinets.[Cabinet ID]) Inner Join
Rooms On Cabinets.[Room ID] = Rooms.RoomNumber) Inner Join
[Job Info] On Rooms.[Job ID] = [Job Info].ID
Group By Drawers.[Drawer ID], Drawers.[Drawer Name], Trim(Drawers.[Width String]) + 'x' + Trim(Drawers.[Height String]) + 'x' + Trim(Drawers.[Depth String]), DrawerCounts.Qty, Drawers.MaterialSchedule, [Job Info].PurchaseOrder
Order By DrawerCounts.Qty,
Drawers.[Drawer Name],
Trim(Drawers.[Width String]) + 'x' + Trim(Drawers.[Height String]) + 'x' + Trim(Drawers.[Depth String]),
Drawers.MaterialSchedule

这是在Microsoft Access中,我无法更改任何表,因此我必须完全在SQL中尝试此操作。

0 个答案:

没有答案