私は実際にこの質問に2つの方法を実装しています.1つは以下の通りです. 最悪。これ、オラクルは問題を示し続けました
from padoctors p right outer join * 行 2 のエラー: ORA-00936: 式がありません
それを手伝ってください
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;
これ、私はhttp://www.oracle-base.com/articles/misc/with-clause.phpで「with」の使用法をグーグルで調べましたが 、まだ機能していません。
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;