0

我实际上在这个问题中实现了两种方法,一种如下,另一种是使用'with'替换子查询,它们都不起作用。糟透了。这个,oracle一直显示问题

来自 padctors p 右外连接 * 第 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;
4

1 回答 1

0

Just Aguy说的话,我玩过,是的:
SELECT DISTINCTIVE * FROM Table确实给出了“ ORA-00936: missing expression
,所以你需要SELECT DISTINCT

于 2013-02-27T09:47:33.450 回答