Esqueleto `selectDistinct` ne fonctionne pas
-
21-12-2019 - |
Question
selectDistinct
ne semble pas fonctionner pour moi, c'est probablement une simple erreur.la requête:
info <- runDB $
E.selectDistinct $
E.from $ \(tp `E.InnerJoin` rnd `E.InnerJoin` h) -> do
E.on (rnd E.^. RoundId E.==. h E.^. HoleRound)
E.on (tp E.^. TpartTournament E.==. rnd E.^. RoundTourn)
E.where_ ((tp E.^. TpartTournament E.==. E.val tId ))
E.orderBy [E.asc (tp E.^. TpartId)]
return (tp, rnd, h)
Je suis sûr que cela représente la requête SQL qui fonctionne :
SELECT DISTINCT tpart.id, round.name, hole.hole_num, hole.score
from tpart
inner join round on round.tourn = tpart.tournament
inner join hole on hole.round = round.id
where tpart.tournament = 1;
Pour afficher les résultats, j'ai un gestionnaire de test pour simplement imprimer le tableau des résultats.Notez que pour la partie 1, tour 1, il y a plusieurs trous 1 et 2.Dans PostgreSQL SELECT DISTINICT
supprimé ces doublons.
TpartId, RoundName, holeNum, HoleScore
Key {unKey = PersistInt64 1}, round 1, 1, 6
Key {unKey = PersistInt64 1}, round 1, 2, 4
Key {unKey = PersistInt64 1}, round 1, 1, 6
Key {unKey = PersistInt64 1}, round 1, 2, 4
Key {unKey = PersistInt64 1}, round 1, 1, 6
Key {unKey = PersistInt64 1}, round 1, 2, 4
Key {unKey = PersistInt64 1}, round 2, 1, 3
Key {unKey = PersistInt64 1}, round 2, 2, 5
Key {unKey = PersistInt64 1}, round 2, 1, 3
Key {unKey = PersistInt64 1}, round 2, 2, 5
Key {unKey = PersistInt64 1}, round 2, 1, 3
Key {unKey = PersistInt64 1}, round 2, 2, 5
Key {unKey = PersistInt64 3}, round 1, 1, 6
Key {unKey = PersistInt64 3}, round 1, 2, 4
Key {unKey = PersistInt64 3}, round 1, 1, 6
Key {unKey = PersistInt64 3}, round 1, 2, 4
Key {unKey = PersistInt64 3}, round 1, 1, 6
Key {unKey = PersistInt64 3}, round 1, 2, 4
Key {unKey = PersistInt64 3}, round 2, 1, 3
Key {unKey = PersistInt64 3}, round 2, 2, 5
Key {unKey = PersistInt64 3}, round 2, 1, 3
Key {unKey = PersistInt64 3}, round 2, 2, 5
Key {unKey = PersistInt64 3}, round 2, 1, 3
Key {unKey = PersistInt64 3}, round 2, 2, 5
Désolé pour l'illisibilité.Toute aide serait appréciée!
La solution
L'erreur était que pour un certain trou, le trou round
ET les trous part
doivent être égaux, ce sont des parties respectives.De plus, la jointure interne était redondante dans cette situation.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow