如何将行转换为oracle 10g中的列(如oracle 11g中的pivot),这样我就可以为主键添加多个“和”条件。
例如:从emp
中选择emp_name其中empid = 1且emp_age = 21; 其中empid = 12和emp_age = 23;
不使用'in',我必须得到满足所有上述条件的记录(比如'和'操作)。
答案 0 :(得分:2)
这blog entry on pivot queries可能会给你一些想法。
答案 1 :(得分: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);