عرض عملي: بناء تقرير المبيعات الشهري بـ SQL
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
build the monthly report as one query that uses CTEs, windows, and FILTER.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Show the Java version that loads all orders and aggregates in memory; note its row count and time.
- Write a CTE
monthlythat groups paid orders bydate_trunc('month', created_at)and category. - Add
rank() OVER (PARTITION BY month ORDER BY revenue DESC)and keep the top 3. - Add
lag(revenue)for month-over-month change andFILTERfor refunded counts. - Planned mistake: put the
rank()condition inWHERE; PostgreSQL rejects it. Fix: wrap in a CTE and filter outside. - Compare time and data transferred with the Java version.
Prepares MID-011-LAB1.
اختبر فهمك
Why is aggregating in SQL usually better than in Java?
أظهر الإجابة
Less data crosses the network and the database is built for it.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.