Domanda

selectDistinct sembra non lavorare per me, è probabilmente un semplice errore. la query:

 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)  
.

Sono abbastanza sicuro che questo rappresenta la query SQL che funziona:

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;
.

Per visualizzare i risultati ho un gestore di prova per stampare semplicemente la tabella dei risultati.Si noti che per TPART 1, round 1, ci sono più fori 1 e foro 2. In PostgreSQL SELECT DISTINICT ha rimosso questi duplicati.

     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
.

Scusa per l'illegibilità.Qualsiasi aiuto sarebbe apprezzato!

È stato utile?

Soluzione

L'errore era che per un certo foro, il round del foro e il part del foro devono essere uguali a rispettare le rispettive parti.Inoltre, il join interiore è stato ridondante in quella situazione.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top