|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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;
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
||||
|
||||
|
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; |
|
#4
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Assigning/Storing Count values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|