SQL
GROUP BY, explained with workout logsGROUP BY بشرح من سجلات التمارين
Imagine a table called workouts with one row per session: the person's name and how many minutes they trained.
You want each person's total minutes.
GROUP BY member puts all rows for the same person into one group, and SUM(minutes) adds up the minutes inside each group.
Easy rule: any column you put in SELECT without a function like SUM or COUNT must also be in GROUP BY.
تخيّل جدول اسمه workouts فيه سطر لكل تمرين: اسم الشخص وعدد الدقائق.
تبغى تعرف كل شخص كم دقيقة تمرّن بالمجموع؟
GROUP BY member تجمع كل السطور لنفس الشخص في مجموعة وحدة، وSUM(minutes) تجمع الدقائق داخل كل مجموعة.
قاعدة سهلة: أي عمود تكتبه في SELECT بدون دالة مثل SUM أو COUNT لازم يكون موجود في GROUP BY.
SELECT member, SUM(minutes) AS total_minutes FROM workouts GROUP BY member;