Create crosstab type query with SELECT only?

D

Dorian

I have a table containing 2 types of record, the type indicated by a certain
column.
There will always be only one record of each type with a common key.
I need to create a query where I combine each pair of rows into a single row.
E.g.
Key 001 Type A 250.00
Key 001 Type B 100.00
Key 002 Type A 125.00
Key 002 Type B 333.00

I need to return 2 rows:
Key 001 A=250 B=100
Key 002 A=125 B=333

How would I do this in a single select statement? I cannot use Transform or
Pivot as this is being run against an Oracle table. I can only use standard
SQL. Thanks.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
K

KARL DEWEY

Try this --
SELECT Key, [YourTable].[Amount] AS [Type A], [YourTable_1].[Amount] AS
[Type B]
FROM [YourTable] INNER JOIN [YourTable_1] ON [YourTable].[Type] =
[YourTable_1].[Type]
WHERE (([YourTable].[Key] = [YourTable_1].[Key]) AND ([YourTable].[Type] =
"A" AND [YourTable_1].[Type] = "B"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top