选择计数内部联接两个数据库

时间:2018-07-12 22:01:09

标签: sql oracle

我想显示按国家/地区分类的所有供应商信息,包括当月提供的名称数量。

这是两个数据库及其变量:

1。供应商:供应商ID,供应商名称,国家/地区,ReliabilityScore,ContactInfo

2.SuppliedName:SnID,Suppliedname1,语言,状态,标准,PlaceID,SupplierID,Supplieddate

这是我想出的并没有真正起作用的内容:

SELECT COUNT(DISTINCT SuppliedName.suppliedname1), Supplier.(*) FROM SuppliedName 
INNER JOIN Supplier ON Supplier.SupplierID = SuppliedName.SupplierID
WHERE EXTRACT(MONTH FROM SuppliedName.Supplieddate)=EXTRACT(MONTH FROM sysdate) AND EXTRACT(YEAR FROM SuppliedName.Supplieddate)=EXTRACT(YEAR FROM sysdate)
ORDER BY Supplier.Country;

请帮助!!!谢谢!

1 个答案:

答案 0 :(得分:1)

我想您只是错过了GROUP BY中所有列的SUPPLIER

SELECT COUNT(DISTINCT SUPPLIEDNAME.SUPPLIEDNAME1),
       SUPPLIER.SUPPLIERID,
       SUPPLIER.SUPPLIEDNAME,
       SUPPLIER.COUNTRY,
       SUPPLIER.RELIABILITYSCORE,
       SUPPLIER.CONTACTINFO
       FROM SUPPLIEDNAME
            INNER JOIN SUPPLIER
                       ON SUPPLIER.SUPPLIERID = SUPPLIEDNAME.SUPPLIERID
       WHERE EXTRACT(MONTH FROM SUPPLIEDNAME.SUPPLIEDDATE) = EXTRACT(MONTH FROM SYSDATE)
             AND EXTRACT(YEAR FROM SUPPLIEDNAME.SUPPLIEDDATE) = EXTRACT(YEAR FROM SYSDATE)
       GROUP BY SUPPLIER.SUPPLIERID,
                SUPPLIER.SUPPLIEDNAME,
                SUPPLIER.COUNTRY,
                SUPPLIER.RELIABILITYSCORE,
                SUPPLIER.CONTACTINFO
       ORDER BY SUPPLIER.COUNTRY;