בעיה בתרגום שאילתה ל־peewee

תגיות:

השגיאה הזאת גם לא הבנתי איך מתעלמים ממנה, זה אומר שהשאילתה שלך מחזירה כלום…

ואני גם תקוע על איך לתרגם עם נכון ל peewe…

SELECT u.user_name as user_name, count(*) AS total_points
FROM users AS u
INNER JOIN games AS g
ON u.user_name = g.user_name
INNER JOIN game_resulte AS r
ON r.game_id = g.game_id
GROUP BY u.user_name
ORDER BY total_points DESC
LIMIT 3;

נדב – מה ניסית לכתוב כדי שזה יעבוד?

top_players = Users.select(Users.user_name, peewee.fn.COUNT().alias('total_points')).join(Games).join(GameResulte).group_by(Users.user_name)

זה נראה בסדר. איפה הבעיה?

Users.select(Users.user_name, peewee.fn.COUNT().alias(‘total_points’)).join(Games).join(GameResulte).group_by(Users.user_name).order_by(Users.user_name.desc())

שאני מוסיף לזה סידור יורד, זה נותן לי בפלט את השאילתה ולא את הנתונים שאמורים לחזור…

כיוון שלא ביקשת את התוצאות. ראינו את זה כמה פעמים ב־live.
נסה עם .dicts או .get. יש פתרונות בתיעוד של peewee

ראה לדוגמה: https://stackoverflow.com/questions/45501197/get-list-of-query-results-in-peewee/45721586
גיגלתי בשביל זה: peewee returns the query instead results

תודה.
מה שעבד בסוף :
query = Users.select(Users.user_name, peewee.fn.COUNT().alias(‘total_points’)).join(Games).join(GameResulte).group_by(Users.user_name).order_by(Users.user_name.desc()).limit(3)
top_players =
for user in query:
top_players += [user.user_name, user.total_points]

לייק 1