質問

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、ラウンド1の場合、複数の穴1とホール2があります.PostgreSQL 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