Oracle: SQL para agrupar subniveles

I have this table, how can I query this table to have sample output below where the passed parameters are Item_Name and Spec_Name Thank you.

Item_Name   Item_Value     Spec_Name   Spec_Value
---------   ----------     ---------   ----------
Circle      Zed Circle     Diameter    180
Circle      Charlo Circle  Diameter    330
Square      Ash Square     Side        120

Sample output for Item_Name=Circle and Spec_Name = Diameter:

 Circle             Zed Circle - Diameter
 -------------     ---------------------
 Zed Circle         180
 Charlo Circle      330

I've try using MAX() function but it only give me 330. :(

Here is the whole query :

     WHEN (ITEM_NAME = 'Circle') THEN
   END AS "Circle",
     WHEN (ITEM_NAME = 'Circle' AND SPEC_NAME = 'Diameter') THEN
   END AS "Circle - Diameter"

Edited the user has tried this, mention in comments.

CASE WHEN (ITEM_NAME = 'Circle' AND SPEC_NAME= 'Diameter') 

gracias de antemano.

preguntado el 04 de julio de 12 a las 05:07

please explain what you are trying to do as what you're doing now will require a simple: select * from table where Item_Name='Circle' and Spec_Name = 'Diameter' -

Sorry made a mistake in the desire output. I tried : CASE WHEN (ITEM_NAME = 'Circle' AND SPEC_NAME= 'Diameter') THEN MAX(SPEC_VALUE) END -

Please post in SQL statement that you have used. also let know the expected output -

1 Respuestas

¿Has probado usar WHERE ?

SELECT item_value AS Circle, spec_value AS Diameter
FROM tbl_shapes
WHERE item_name = 'Circle' AND spec_name = 'Diameter'
ORDER BY spec_value

Respondido 04 Jul 12, 05:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.