首先我做了:
CREATE TABLE Persons (
id INTEGER not null,
capital_loss INTEGER,
capital_gain INTEGER,
salary INTEGER,
PRIMARY KEY ( id )
);
我想获得一行的id和薪水:
max(capital_gain-capital_loss) and salary =50
先谢谢
答案 0 :(得分:0)
这个怎么样
select id, salary, max(capital_gain - capital_loss)
from Persons
where salary = 50
group by id, salary
答案 1 :(得分:0)
记住你的条件(无论从所有最大行返回哪一行),以及你是否使用mysql:
SELECT id, salary FROM Persons
WHERE salary=50
ORDER BY (capital_gain - capital_loss) DESC LIMIT 1;