문제

selectDistinct 나에게는 작동하지 않는 것 같습니다. 아마도 단순한 오류일 것입니다.쿼리:

 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)  

나는 이것이 작동하는 SQL 쿼리를 나타낸다고 확신합니다.

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;

결과를 보기 위해 결과 테이블을 인쇄하는 테스트 핸들러가 있습니다.tpart 1, round 1의 경우 구멍 1과 구멍 2가 여러 개 있습니다.포스트그레SQL에서 SELECT DISTINICT 이 중복 항목을 제거했습니다.

     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

읽기 불편해서 죄송합니다.어떤 도움이라도 주시면 감사하겠습니다!

도움이 되었습니까?

해결책

오류는 특정 구멍에 대한 것입니다. round 그리고 홀의 part 그것들은 각각의 부분과 동일해야 합니다.또한 해당 상황에서는 내부 조인이 중복되었습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top