Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Query Optimization | Section
Advanced SQL for Backend Developers
Секція 1. Розділ 14
single

single

bookChallenge: Query Optimization

Свайпніть щоб показати меню

Assume we want to retrieve only the account numbers that have performed at least one transaction.

In this task, we have a query that is not optimized. Your task is to rewrite it in a more optimal way.

Here is a list of the main query rewriting techniques to enhance optimization:

  1. Explicitly Specify Columns: instead of using the asterisk (*) wildcard, explicitly mention column names in queries for better performance, readability, and maintainability;

  2. Minimize Subqueries: reduce the use of subqueries to optimize query performance. Consider alternatives like joins or derived tables to avoid complexity and overhead;

  3. Avoid Repeated IN Operators: limit the use of the IN operator in queries to prevent performance impact. Instead, consider using JOIN or EXISTS clauses for more efficient execution plans;

  4. Organize Joins Logically: start SQL joins with the main table and then join with related tables to optimize query organization and database engine optimization;

  5. Use Restrictive WHERE Conditions: improve query performance by including restrictive conditions in the WHERE clause to filter rows and enhance execution speed;

  6. Refactor Code into Stored Procedures or Functions: encapsulate repetitive code segments into stored procedures or user-defined functions for code reusability, modularity, and easier maintenance. These can reduce redundancy and optimize SQL queries.

Завдання

Swipe to start coding

Your task is to write a query that returns a list of all account numbers that have performed at least one transaction (transferred money to another account). The results should be sorted in ascending order by account number.

To make your query more efficient and readable, follow these steps:

  • Select only the account_number column;
  • Use an INNER JOIN between the BankAccounts and Transactions tables;
  • Do not use the IN operator or subqueries;
  • Sort the result by account_number in ascending order.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 14
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt