我想知道是否有其他方法来编写此查询

时间:2016-12-05 09:34:19

标签: sql

SELECT orderyear, numcusts
FROM (SELECT orderyear, COUNT (DISTINCT custid) AS numcustd
        FROM (SELECT YEAR ()orderdate) AS orderyear, custid
 FROM sales,Orders) AS D1
GROUP BY orderyear) AS D2

WHERE numcusts > 70;

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT D1.orderyear, D1.numcustd
FROM (
        SELECT YEAR(orderyear) as orderyear, COUNT (DISTINCT custid) AS numcustd
        FROM sales,Orders
        GROUP BY orderyear 
                            ) AS D1
WHERE numcusts > 70;