how can i convert rows in to columns in oracle 10g( like pivot in oracle 11g),so that i can add multiple 'and' conditions for the primary key.
ex: select emp_name from emp
where empid = 1 and emp_age = 21; where empid = 12 and emp_age = 23;
without using 'in' ,i have to get records which satisfies all th开发者_运维问答e above condtions(Like 'and ' operation).
This blog entry on pivot queries may give you some ideas.
There is no easy way to do this in sql. If you know how many columns you need read this: 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);
精彩评论