Pregunta

selectDistinct Parece que no me funciona, probablemente sea un simple error.la consulta:

 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)  

Estoy bastante seguro de que esto representa la consulta SQL que funciona:

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;

Para ver los resultados, tengo un controlador de pruebas para simplemente imprimir la tabla de resultados.Observe que para la parte 1, ronda 1, hay varios orificios 1 y 2.en postgresql SELECT DISTINICT eliminó estos duplicados.

     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

Perdón por la ilegibilidad.¡Cualquier ayuda sería apreciada!

¿Fue útil?

Solución

El error fue que para un determinado agujero, el agujero del agujero round Y el agujero part deben ser iguales, son partes respectivas.Además, la unión interna era redundante en esa situación.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top