Home » SQL & PL/SQL » SQL & PL/SQL » oracle (10g)
oracle [message #347285] Thu, 11 September 2008 04:29 Go to next message
pavan2008
Messages: 2
Registered: September 2008
Location: SYDNEY
Junior Member
hi,

an new to sql...i have a table called tags
tags
---------
passed
issued
failed


i need to write a cursor/query which results as

passed*4+issued*2.6-failed*2


can any one pls help in this matter
Re: oracle [message #347300 is a reply to message #347285] Thu, 11 September 2008 04:48 Go to previous messageGo to next message
Michel Cadot
Messages: 64119
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide:
- Format your post
- Post your Oracle version (4 decimals)
- Post a test case
- Post what you tried
- Search as this (or closed) has already been asked

Regards
Michel
Re: oracle [message #347333 is a reply to message #347285] Thu, 11 September 2008 05:35 Go to previous messageGo to next message
dwarak.k
Messages: 61
Registered: June 2008
Location: Hyderabad
Member
Considering passed,issued,failed are your tags table's columns,

select (passed*4)+(issued*2.6)-(failed*2) as result 
from tags


Refer
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
Re: oracle [message #347384 is a reply to message #347285] Thu, 11 September 2008 07:50 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
pavan2008 wrote on Thu, 11 September 2008 05:29
hi,

an new to sql...i have a table called tags
tags
---------
passed
issued
failed


i need to write a cursor/query which results as

passed*4+issued*2.6-failed*2


can any one pls help in this matter


You cannot multiple strings by numbers.
Re: oracle [message #347398 is a reply to message #347384] Thu, 11 September 2008 08:34 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
If what you want is
<number of rows with a value  of passed>*4+
<number of rows with a value of issued>*2.6-
<number of rows with a value of failed>*2

Then you coud use a construct like this:
SELECT sum(case when value = 'passed' then 4
                when value = 'issued' then 2.6
                when value = 'failed' then -2
                else 0 end
FROM table;
Previous Topic: Getting the function value with arguments by using execute immediate
Next Topic: Master/Details tables "mutating" error on CASCADE delete
Goto Forum:
  


Current Time: Tue Dec 06 10:28:32 CST 2016

Total time taken to generate the page: 0.10823 seconds