2010-08-18 45 views
1

如何將行轉換爲Oracle 10g中的列(如Oracle 11g中的pivot),以便我可以爲主鍵添加多個'和'條件。將行轉換爲oracle10g中的列

例如:從EMP選擇EMP_NAME

其中EMPID = 1和emp_age = 21; 其中empid = 12和emp_age = 23;

沒有使用'in',我必須得到滿足所有上述條件的記錄(如'和'操作)。

回答

0

在sql中沒有簡單的方法來做到這一點。如果你知道你有多少列需要閱讀: http://thinkoracle.blogspot.com/2005/09/pivot-and-crosstab-queries.html

CREATE TABLE CFL (season NUMBER(4), team VARCHAR2(16), points NUMBER(3)); 
INSERT INTO CFL (season, team, points) VALUES (2004, 'Argonauts', 21); 
INSERT INTO CFL (season, team, points) VALUES (2004, 'Alouettes', 28); 
INSERT INTO CFL (season, team, points) VALUES (2004, 'Tiger-Cats', 19); 
INSERT INTO CFL (season, team, points) VALUES (2004, 'Renegades', 10); 
INSERT INTO CFL (season, team, points) VALUES (2003, 'Argonauts', 18); 


SELECT team, 
DECODE (season, 2002, points, NULL) Yr2002, 
DECODE (season, 2003, points, NULL) Yr2003, 
DECODE (season, 2004, points, NULL) Yr2004 
FROM (SELECT season, team, points FROM CFL); 
+0

解碼語句等效,IF-THEN-ELSE聲明: 但我需要添加condtion爲其中季= 2002點= 10,其中季= 2003點= 26 對於上述地方condtion我需要應用'AND'操作。有什麼辦法可以得到。 – gokul 2010-08-18 13:21:18