我正在使用此查询来获取total_votes最大的行,但此查询不返回任何行,因此它应返回1行。请帮忙。
SELECT assembly, seat_code, CONCAT(first_name,' ',last_name), total_votes, party_id
FROM polling JOIN seat USING (seat_id) JOIN candidate USING (candidate_id)
WHERE seat_id=1
HAVING total_votes = MAX(total_votes);
答案 0 :(得分:0)
您可以使用MAX
聚合并删除HAVING
子句。见下文:
SELECT * FROM
(
SELECT
assembly,
seat_code,
CONCAT(first_name,' ',last_name)name,
MAX(total_votes)total_votes,
party_id
FROM polling JOIN seat USING (seat_id) JOIN candidate USING (candidate_id)
WHERE seat_id=1
) AS A
HAVING total_votes=(SELECT MAX(total_votes) FROM polling )
答案 1 :(得分:0)
select assembly, seat_code, concat(first_name,' ',last_name), total_votes, party_id
from (polling join seat using(seat_id) join candidate using(candidate_id))
where seat_id=1 and total_votes=(select max(total_votes) from <table name>);
使用此