-1

好的,所以我需要计算“resource_ID”在我的表中出现少于 3 次的次数,然后从另一个表链接资源描述。

到目前为止我有

Select Resource_hire.Resource_ID, count(resource_ID) as Times_Used  

from RESOURCE_HIRE

Group by resource_ID

HAVING COUNT(*)< 3;

但是当我添加

SELECT RESOURCE_INVENTORY.DESCRIPTION, RESOURCE_HIRE.RESOURCE_ID

FROM RESOURCE_HIRE, RESOURCE_INVENTORY

WHERE (RESOURCE_HIRE.RESOURCE_ID = RESOURCE_INVENTORY.R_ID)

INNER JOIN (Select Resource_hire.Resource_ID, count(resource_ID)
from RESOURCE_HIRE

Group by resource_ID

HAVING COUNT(*)< 3;)

i Get SQL 命令未正确结束

谢谢

4

1 回答 1

0

You are trying to use the joins in a wrong manner.

Try this:

  SELECT ri.DESCRIPTION, rh.RESOURCE_ID
    FROM RESOURCE_HIRE rh
         INNER JOIN (Select Resource_hire.Resource_ID, count(resource_ID)
                       from RESOURCE_HIRE
                      Group by resource_ID
                     having COUNT(*)< 3;) rh
         ON (rh.RESOURCE_ID = ri.R_ID)

You cannot use the JOIN keyword and joining in the WHERE clause at the same time.

More on joins on Oracle Docs.

于 2013-05-06T14:56:14.473 回答