Esqueleto `selectDistinct` لا يعمل
-
21-12-2019 - |
سؤال
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.في ما بعد Gresql 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
يجب أن تكون متساوية في الأجزاء المعنية.كما أن الصلة الداخلية كانت زائدة عن الحاجة في تلك الحالة.
لا تنتمي إلى StackOverflow