1

我做了这个查询,现在我必须找到不同的方法来返回相同的结果。

SELECT CompanyName, COUNT(Orders.OrderID) Orders
FROM Customers LEFT OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID
WHERE Country LIKE 'Germany' OR Country LIKE 'Brazil' 
GROUP BY CompanyName HAVING COUNT(Orders.OrderID) >= 10
ORDER BY Orders ASC;

所以我做了这个,但我不知道应该把“> = 10”条件放在哪里。有人可以告诉我该怎么做吗?我尝试了一些方法,但没有奏效。

SELECT CompanyName, (SELECT COUNT(OrderID) FROM Orders WHERE Customers.CustomerID = Orders.CustomerID) AS Orders
FROM Customers
WHERE Country LIKE 'Germany' OR Country LIKE 'Brazil'
ORDER BY Orders ASC;

它适用于 MS SQL Server...

4

2 回答 2

0
   SELECT CompanyName, COUNT(Orders.OrderID) Orders
   FROM Customers JOIN Orders ON Customers.CustomerID = Orders.CustomerID
   WHERE Country IN('Germany','Brazil') 
   GROUP BY CompanyName 
   HAVING COUNT(Orders.OrderID) >= 10
   ORDER BY Orders ASC;
于 2013-10-29T13:29:39.403 回答
0
SELECT
      COMPANYNAME,
      ( SELECT
            COUNT ( ORDERID )
       FROM
            ORDERS
       WHERE
            CUSTOMERS.CUSTOMERID = ORDERS.CUSTOMERID
       HAVING
            COUNT ( ORDERID ) >= 10 )
          AS ORDERS
FROM
      CUSTOMERS
WHERE
      COUNTRY LIKE 'Germany'
      OR COUNTRY LIKE 'Brazil'
ORDER BY
      ORDERS ASC;
于 2013-10-29T11:12:00.837 回答