我怎样才能改变这个查询,我想把最大值变成一个子查询,当我输入sql时,唯一会出现的是id和名字。
SELECT staff.staff_id,staff.firstname,max(payment.amount) from payment ,staff where payment.staff_id=staff.staff_id
kb5ga3dv1#
从 JOIN 到(相关)子查询:
JOIN
SELECT staff.staff_id, staff.firstname, (SELECT MAX(payment.amount) FROM payment WHERE payment.staff_id = staff.staff_id) FROM staff
vltsax252#
使用显式联接
SELECT staff.staff_id,staff.firstname,max(payment.amount) from payment join staff on payment.staff_id=staff.staff_id
但我想你想
SELECT staff.staff_id,staff.firstname,p.amount from payment p join staff on p.staff_id=staff.staff_id where p.amount= select max(amount) from payment
ojsjcaue3#
可以尝试使用相关子查询
SELECT staff.staff_id,staff.firstname from payment inner join staff on payment.staff_id=staff.staff_id where payment.amount in (select max(payment.amount) from payment)
3条答案
按热度按时间kb5ga3dv1#
从
JOIN
到(相关)子查询:vltsax252#
使用显式联接
但我想你想
ojsjcaue3#
可以尝试使用相关子查询