convert row into columns in oracle10g

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

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).

回答1:

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



回答2:

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);


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!