I
IanONet
I have avoided Crosstab queries for too long. Now is the time for me to
"get it".
So I attempted to do the query from the Northwind example in the help.
Here is the data from the Select query:
Last Name Category Sum of Subtotal
Buchanan Beverages $13,517.50
Buchanan Condiments $2,802.45
Buchanan Confections $5,489.05
Buchanan Dairy Products $23,850.40
Buchanan Grains/Cereals $4,233.25
Buchanan Meat/Poultry $11,869.40
Buchanan Produce $7,605.10
Buchanan Seafood $6,200.60
Callahan Beverages $18,640.80
Callahan Condiments $15,447.95
Callahan Confections $22,639.50
and the SQL for that query:
SELECT Employees.LastName, Products.CategoryID AS [Category Name],
Sum(([Order Details].[UnitPrice]*[Quantity])) AS [Sum of Subtotal]
FROM Products INNER JOIN ((Employees INNER JOIN Orders ON
Employees.EmployeeID = Orders.EmployeeID) INNER JOIN [Order Details] ON
Orders.OrderID = [Order Details].OrderID) ON Products.ProductID =
[Order Details].ProductID
GROUP BY Employees.LastName, Products.CategoryID
ORDER BY Employees.LastName, Products.CategoryID;
Now the task is to rearrange the data so I get the Categories on the
top row and the last names in the first column. The dollar amount
should fill the field.
I know I am confused by what it wants for row headers and column
headers.
Here is my attempt in SQL:
TRANSFORM Sum(qselGOsInTo.[Sum of Subtotal]) AS [SumOfSum of Subtotal]
SELECT qselGOsInTo.LastName, qselGOsInTo.[Category Name]
FROM qselGOsInTo
GROUP BY qselGOsInTo.LastName, qselGOsInTo.[Category Name]
PIVOT qselGOsInTo.[Category Name];
I'd appreciate it if someone could fix that query AND explain just how
I am supposed to think about the data in this transformation process.
Just what goes into the TRANSFORM clause and why?
Just what goes into the PIVOT clause and why?
I suspect that I have the group by correct ;-)
Thanks in advance,
IanO
"get it".
So I attempted to do the query from the Northwind example in the help.
Here is the data from the Select query:
Last Name Category Sum of Subtotal
Buchanan Beverages $13,517.50
Buchanan Condiments $2,802.45
Buchanan Confections $5,489.05
Buchanan Dairy Products $23,850.40
Buchanan Grains/Cereals $4,233.25
Buchanan Meat/Poultry $11,869.40
Buchanan Produce $7,605.10
Buchanan Seafood $6,200.60
Callahan Beverages $18,640.80
Callahan Condiments $15,447.95
Callahan Confections $22,639.50
and the SQL for that query:
SELECT Employees.LastName, Products.CategoryID AS [Category Name],
Sum(([Order Details].[UnitPrice]*[Quantity])) AS [Sum of Subtotal]
FROM Products INNER JOIN ((Employees INNER JOIN Orders ON
Employees.EmployeeID = Orders.EmployeeID) INNER JOIN [Order Details] ON
Orders.OrderID = [Order Details].OrderID) ON Products.ProductID =
[Order Details].ProductID
GROUP BY Employees.LastName, Products.CategoryID
ORDER BY Employees.LastName, Products.CategoryID;
Now the task is to rearrange the data so I get the Categories on the
top row and the last names in the first column. The dollar amount
should fill the field.
I know I am confused by what it wants for row headers and column
headers.
Here is my attempt in SQL:
TRANSFORM Sum(qselGOsInTo.[Sum of Subtotal]) AS [SumOfSum of Subtotal]
SELECT qselGOsInTo.LastName, qselGOsInTo.[Category Name]
FROM qselGOsInTo
GROUP BY qselGOsInTo.LastName, qselGOsInTo.[Category Name]
PIVOT qselGOsInTo.[Category Name];
I'd appreciate it if someone could fix that query AND explain just how
I am supposed to think about the data in this transformation process.
Just what goes into the TRANSFORM clause and why?
Just what goes into the PIVOT clause and why?
I suspect that I have the group by correct ;-)
Thanks in advance,
IanO