我導入電子數據表,它包含在同一列作爲子父組數據。如下所示,我想爲組添加提取列。
創建表
DECLARE @Fruit TABLE
(
ProductID INT IDENTITY(1, 1)
PRIMARY KEY ,
FruitName NVARCHAR(20) ,
FruitCost MONEY
)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('Berry', NULL)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('BlueBerry', 2)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('StrawBerry', 2)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('Citrus', NULL)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('Lemon', 2)
INSERT INTO @fruit
(FruitName, FruitCost)
VALUES ('Orange', 2)
SELECT *
FROM @Fruit
表結果
ProductID FruitName FruitCost
----------- -------------------- ---------------------
1 Berry NULL
2 BlueBerry 2.00
3 StrawBerry 2.00
4 Citrus NULL
5 Lemon 2.00
6 Orange 2.00
需要的結果
FruitName FruitCost FruitGroup
-------------------- --------------------- --------------------
BlueBerry 2.00 Berry
StrawBerry 2.00 Berry
Lemon 2.00 Citrus
Orange 2.00 Citrus
這是功課?另外,你怎麼知道檸檬是柑橘類水果? – podiluska 2012-08-15 11:35:48
我希望這是希望的工作。想讓我改變成合適的欄目,否則如果你不能保持獨立。 – 2012-08-15 11:39:39