内部加入和计数抛出错误

时间:2018-02-23 10:42:07

标签: sql oracle join oracle10g

对于SQL而言,我仍然是一个新手,我想知道你是否可以提供帮助。我被要求加入两个表(我假设是一个内连接)并对结果进行计数和分组。

我写的代码是:

SELECT publisher.name, printjob.JobNo, r.CountPO
    FROM Publisher, PrintJob
    INNER JOIN  (SELECT purchaseorder.orderno count (*) as CountPO, FROM purchaseorder
GROUPBY publisher.name) as r ON 
as ORDER BY publisher.name;

但是它声明FROM不是应该的位置。我不确定如果是这样,任何建议都会非常感激。

的Ta!

编辑:好的,我已将上述内容更正为:

SELECT PrintJob.JobNo,count(*)as POS FROM PurchaseOrder INNER JOIN PrintJob WHERE purchaseorder.printjob = printjob.jobno GROUP BY publisher.name;

仍然无处可去。

哭声

1 个答案:

答案 0 :(得分:1)

你在错误的地方昏迷:

SELECT purchaseorder.orderno, count (*) as CountPO FROM purchaseorder
GROUPBY publisher.name

你需要在内部查询中进行分组。 在ON之后你需要一些连接条件。

在一个查询中使用两种类型的连接也不好:

FROM Publisher, PrintJob

应该通过加入随处可见:

FROM Publisher as p
inner join PrintJob as pj on [some condition]
INNER JOIN  (SELECT purchaseorder.orderno count (*) as CountPO, FROM purchaseorder
GROUPBY publisher.name) as r ON [some condition]