Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 15th, 2005, 05:15 AM
Michal Augustyn Michal Augustyn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 103 Michal Augustyn User rank is Private First Class (20 - 50 Reputation Level)Michal Augustyn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 44 m 16 sec
Reputation Power: 4
Assigning/Storing Count values

Hi!

Here's what I'm trying to do:

I'd like to calculate the value of a recurring attribute and then use it in
an artithmetic statement.

My original equation was

select
v1.medicareid, (a1.datedischarged - a1.dateadmitted)*500 + count(v1.medicareid)*d1.visitfee
from
admission a1, doctor d1, visit v1
where
v1.medicareid = 'abcdefghik' and
a1.medicareid = v1.medicareid and
d1.eid = v1.doctorid;

Everything works fine until count(v1.medicareid)*d1.visitfee (I tried it without this statement).

But when I add the above statement it outputs an ORA-00936 error, i.e. that the beginning of the line is not a single-group group function.

What I tried next is to separate the two statements and have the date calculation be performed at a later time and first, I'd calculate the occurrence of the medicare id using:

select
count(v1.medicareid)
from
visit v1
where
v1.medicareid = 'theidnumber';

How on earth do you store this result??

I tried assigning the entire statement as an insert value to no avail.

Basically if I could store it in some table, then I could retrieve it later. Better yet if I could store it in some variable, but we can't do that outside a table in sqlplus, or can we?

Reply With Quote
  #2  
Old July 15th, 2005, 05:33 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 14 h 31 m 53 sec
Reputation Power: 279
You might try something like:
Code:
SELECT
v1.medicareid, (a1.datedischarged - a1.dateadmitted)*500 + count(v3.c_medicare)*d1.visitfee
FROM
(SELECT count(v2.medicareid) c_medicare FROM visit v2) V3, 
admission a1, doctor d1, visit v1
WHERE
v1.medicareid = 'abcdefghik' and
a1.medicareid = v1.medicareid and
d1.eid = v1.doctorid;

Reply With Quote
  #3  
Old July 15th, 2005, 05:37 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 14 h 31 m 53 sec
Reputation Power: 279
Or maybe:
Code:
SELECT
v1.medicareid, (a1.datedischarged - a1.dateadmitted)*500 + count(v3.c_medicare)*d1.visitfee
FROM
(SELECT 'abcdefghik' medicareid, count(v2.medicareid) c_medicare FROM visit v2) v3, 
admission a1, doctor d1, visit v1
WHERE
v1.medicareid = 'abcdefghik' AND
a1.medicareid = v1.medicareid AND
d1.eid = v1.doctorid
AND v3.medicareid = v1.medicareid;

Reply With Quote
  #4  
Old July 15th, 2005, 06:45 PM
michaeljshannon michaeljshannon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 26 michaeljshannon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 38 m 15 sec
Reputation Power: 0
You need to look into the GROUP predicate.

select var1,
count(var1),
var2,
count(var1) + count(var2)
from tablename
group by var1,
var2

The error you received was because you were mixing a grouped value ( count ) and a non-grouped value ( id ).

You might just try adding the following:

select
v1.medicareid, (a1.datedischarged - a1.dateadmitted)*500 + count(v1.medicareid)*d1.visitfee
from
admission a1, doctor d1, visit v1
where
v1.medicareid = 'abcdefghik' and
a1.medicareid = v1.medicareid and
d1.eid = v1.doctorid
group by v1.medicareid;

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Assigning/Storing Count values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT