views:

84

answers:

2

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 the above condtions(Like 'and ' operation).

A: 

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);
iddqd
decode statement is equivalent to , IF-THEN-ELSE statement:but i need to add condtion as where season =2002 and points =10 , where season =2003 and points =26 for the above where condtion i need to apply 'AND' operation. is there any way to get.
gokul
+2  A: 

This blog entry on pivot queries may give you some ideas.

Tony Andrews