Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Using Window Function | Triggers, Window Functions and DCL
SQL Optimization and Query Features
Osio 3. Luku 4
single

single

Challenge: Using Window Function

Pyyhkäise näyttääksesi valikon

In this challenge, you will put your understanding of window functions into practice. You are provided with a database containing employees and their sales. Your goal is to write a SQL query that calculates each employee's total sales and their rank among all employees based on these totals.

You should use the SUM() window function to compute the total sales for each employee, and the RANK() window function to assign a rank, where the employee with the highest total sales is ranked 1. Both calculations should be performed in a single query, and the results should include each employee's ID, name, total sales, and rank.

Tehtävä

Pyyhkäise aloittaaksesi koodauksen

Write a SQL query to display each employee's total sales and their rank among all employees based on total sales. Use the provided employees and sales tables.

  • Calculate the total sales for each employee using the SUM() window function.
  • Assign a rank to each employee based on their total sales, with the highest total sales receiving rank 1, using the RANK() window function.
  • Display the employee's ID, name, total sales, and rank in the result.
  • Order the results by the employee's rank.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt