2014-02-24 40 views

回答

0

你的意思是這樣的:

SELECT SUM(Salary) 
FROM (
    SELECT Salary FROM your_table ORDER BY id LIMIT 3 
) A 
0

假設它是SQL服務器:

SELECT SUM(Salary) As SalaryTotal 
( 
    SELECT TOP 3 * FROM your_table ORDER BY ID 
) 

如果你想SUM最高3倍的工資,那麼你可以ORDER BY月薪:

SELECT SUM(Salary) As SalaryTotal 
( 
    SELECT TOP 3 * FROM your_table ORDER BY salary DESC  
) 
1

試試用這個.....

SELECT SUM(salary) 
FROM 
    (SELECT 
     ROW_NUMBER() OVER (ORDER BY id ASC) AS ROW_NUMBER, salary 
    FROM tablename) AS foo 
WHERE 
    ROW_NUMBER <= 3