Fast geschafft. Es fehlt nur eine filter-Klausel, um die Stimme des aktuellen Benutzers zu berechnen:
SELECT post.postID AS postID,
post.title AS title,
post.author AS author,
post.created AS created,
COALESCE(sum(votes.vote), 0) AS voteCount,
COALESCE(sum(votes.vote)
FILTER (WHERE votes.username = 'username'), 0) AS userVote
-- in '' einfach den Benutzernamen des eingeloggten Nutzers einsetzen
FROM post
LEFT JOIN votes ON post.postID = votes.postID
GROUP BY 1,2,3,4
ORDER BY 5 DESC;
Alternativ ein zweiter LEFT JOIN:
SELECT p.postID AS postID,
p.title AS title,
p.author AS author,
p.created AS created,
COALESCE(sum(v1.vote), 0) AS voteCount,
COALESCE(v2.vote, 0) AS userVote
FROM post p
LEFT JOIN votes v1 ON p.postID = v1.postID
LEFT JOIN votes v2 ON p.postID = v2.postID AND v2.username = 'username'
GROUP BY 1,2,3,4,v2.vote
ORDER BY 5 DESC;
Die FILTER-Variante ist in der Regel vorzuziehen: kompakter, ein Join weniger und keine zusätzliche Gruppierung über v2.vote.