I actually implement 2 methods in this question, one is as below, the other is using 'with' to substitute the sub queries, neither of them worked. sucks. this one,oracle kept showing the problem
from padoctors p right outer join * ERROR at line 2: ORA-00936: missing expression
please help me with that
select distinctive *
from padoctors p right outer join
(select drug,month,max(drug_num) max_no
from (select drug,count(*) as drug_num,to_char(prescdate,'MM') as month
from padoctors
where to_char(prescdate,'YYYY')='2012'
group by to_char(prescdate,'MM'),drug)
group by month,drug) dmax on p.drug=dmax.drug
full outer join
(select drug,month,min(drug_num) min_no
from (select drug,count(*) as drug_num,to_char(prescdate,'MM') as month
from padoctors
where to_char(prescdate,'YYYY')='2012'
group by to_char(prescdate,'MM'),drug)
group by month,drug) dmin on dmax.month=dmin.month and dmin.drug=p.drug
order by month asc;
this one, I google the usage of 'with' in http://www.oracle-base.com/articles/misc/with-clause.php Still,not working.
with dmax as
(
select drug,month,max(drug_num)
from (select drug,count(*) as drug_num,to_char(prescdate,'MM') as month
from padoctors
where to_char(prescdate,'YYYY')='2012'
group by to_char(prescdate,'MM'),drug
)
group by month,drug
),
dmin as
(
select drug,month,min(drug_num)
from (select drug, count(*) as drug_num, to_char(prescdate,'MM') as month
from padoctors
where to_char(prescdate,'YYYY')='2012'
group by to_char(prescdate,'MM'),drug
)
group by month,drug
)
select distinctive *
from dmax join dmin on dmax.month=dmin.month
order by month asc;
Taking what Just Aguy says, I played with that and yes :
SELECT DISTINCTIVE * FROM Table
does give " ORA-00936: missing expression "
so you'll need SELECT DISTINCT
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.