انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-011-L07

عرض عملي: بناء تقرير المبيعات الشهري بـ SQL

  • الدرس 7 من 7
  • Mid-level
في هذا الدرس 3 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

build the monthly report as one query that uses CTEs, windows, and FILTER.

تفاصيل المخطط المبدئي

خطوة بخطوة

  1. Show the Java version that loads all orders and aggregates in memory; note its row count and time.
  2. Write a CTE monthly that groups paid orders by date_trunc('month', created_at) and category.
  3. Add rank() OVER (PARTITION BY month ORDER BY revenue DESC) and keep the top 3.
  4. Add lag(revenue) for month-over-month change and FILTER for refunded counts.
  5. Planned mistake: put the rank() condition in WHERE; PostgreSQL rejects it. Fix: wrap in a CTE and filter outside.
  6. 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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.