2017-09-19 71 views

回答

0

表T2將返回小於5000的員工列表,然後將其與員工主表T2一起加入。根據需要更改表名。

SELECT * FROM EMPLOYEE T1 JOIN 
(SELECT EmployeeID,SUM(AMOUNT) AMOUNT FROM PRODUCT 
GROUP BY EmployeeID 
HAVING SUM(AMOUNT)<5000) T2 ON T1.EmployeeID=T2.EmployeeID 
0

如果使用上面的SQL Server 2012:

SELECT * 
FROM ( SELECT * , 
        SUM(AMOUNT) OVER (PARTITION BY EmployeeID) AS EmpTotal 
      FROM PRODUCT 
     ) t 
WHERE t.EmpTotal > 5000; 
1

sample data

考慮到上述的圖像作爲虛擬表,您可以使用此查詢讓你適當的結果

SELECT productid, price + productid as Amount 
FROM Products 
where Amount < 15 
order by productid 

該查詢的執行結果如下圖所示:

Result