Roy Harvey
3/20/2007 5:24:00 PM
The key to this is your statement:
>To end users Type is classified in Type A, B and C
>where
>End User Type A = Type 2
>End User Type B = Type 1 and Type 3
>End User type C = Type 4 and Type 5
If that is how your end users see the world, then the database should
reflect that. Create a table, it might be called EndUserTypes, with
one column for the type as the users think of them and one for the
type in the Product table. Populate the table with the 5 rows needed.
Then join to that table when you need the end user's view, and group
on the end user type retrieved.
CREATE TABLE EndUserTypes
( UserUserType char(1) NOT NULL,
Type int NOT NULL)
INSERT EndUserTypes VALUES ('A', 2)
INSERT EndUserTypes VALUES ('B', 1)
INSERT EndUserTypes VALUES ('B', 3)
INSERT EndUserTypes VALUES ('C', 4)
INSERT EndUserTypes VALUES ('C', 5)
SELECT P.productID, U.EndUserType, SUM(P.Quantity) as Quantity
FROM Product as P
JOIN EndUserTypes as U
ON O.Type = U.Type
GROUP BY P.productID, U.EndUserType
Roy Harvey
Beacon Falls, CT
On 20 Mar 2007 10:01:17 -0700, "donet programmer" <arpit.00@gmail.com>
wrote:
>I am trying to write a query which looks something like below:
>
>Product Table:
>ProductId int
>Type int
>Quantity int
>
>Type in the table above can have any value between 1 and 5. There can
>be multiple records in table with same ProductId and Type.
>
>To end users Type is classified in Type A, B and C
>where
>End User Type A = Type 2
>End User Type B = Type 1 and Type 3
>End User type C = Type 4 and Type 5
>
>I want to write a query to get quantity for each product by type so my
>query will return 3 columns: ProductId, Type and Quantity where Type
>will be either A, B or C.
>
>The problem I am facing is how do I group this 1 and 3 and 4 and 5
>together ... :-(
>
>I would appreciate any ideas, help and suggestions
>Thanks