Challenge #6

Challenge #6

Question

Consider the following employees table:

employees

Exercise

Write a SQL query to retrieve the names of employees who have a salary greater than $50,000, and list the employee names in alphabetical order.

The solution to this exercise can be found below - please take some time to work on the solution by yourself first before reading any further.



Solution

Query

Please note that the code below may not be visible if you are reading this article in your email. Kindly read the article on LinkedIn to access it.

SELECT employee_name
  FROM employees
 WHERE salary > 50000
 ORDER BY employee_name;        

Result

SQL Tips

  1. Sorting Data: The ORDER BY clause is used to sort the result set in ascending (default) or descending order based on one or more columns. In this exercise, we are sorting by the employee_name column.
  2. ASC and DESC Keywords: Sorting can be done in ascending order (default) by not specifying ASC, or you can explicitly specify ASC as well but it's not required; just as in our solution we preferred not to specify it. To sort in descending order, use DESC.
  3. Optimizing for Readability: Use indentation and formatting to make your SQL queries more readable. Well-formatted queries are easier to understand and maintain, especially when dealing with complex statements.



Feel free to comment your findings!



If you don't want to miss the carefully crafted SQL challenges every week, subscribe to my Newsletter. Elevate your skills through practice and unlock expert tips; be on top of your game!

Abdallah Yashir Ramsing

Senior Software Developer @ Dayforce | Tech Enthusiast | Co-Founder of TechNews

1 年

What if I want to know the percentage of employees making between $30000 and $50000? ??

要查看或添加评论,请登录

Mehfooz Kausmally的更多文章

  • SQL Challenge #15

    SQL Challenge #15

    Question Consider the following Products and SalesOrders tables: Products SalesOrders Exercise Write a SQL query to…

  • SQL Challenge #14

    SQL Challenge #14

    Question Consider the following products table: products Exercise Write a SQL query to delete all products from the…

  • SQL Challenge #13

    SQL Challenge #13

    Question Consider the following employees table: employees The column stores the ID of the manager for each employee…

    2 条评论
  • SQL Challenge #12

    SQL Challenge #12

    Question Consider the following sales table: sales Exercise Write a SQL query to calculate the average sale amount for…

    3 条评论
  • SQL Challenge #11

    SQL Challenge #11

    Question Consider the following students table: students Exercise Write a SQL query to retrieve the names of students…

    1 条评论
  • SQL Challenge #10

    SQL Challenge #10

    Question Which of the following SQL statements is used to combine the results of two or more SELECT statements and…

  • SQL Challenge #9

    SQL Challenge #9

    Question Examine this list of requirements for a sequence: Name: EMP_SEQ First value returned: 1 Duplicates are never…

  • SQL Challenge #8

    SQL Challenge #8

    Question Consider the following employees table: employees Exercise Write a SQL query to retrieve the top 3 highest…

    1 条评论
  • SQL Challenge #7

    SQL Challenge #7

    Question An important migration is under process to transfer orders information from a staging table (staging_orders)…

  • Challenge #5

    Challenge #5

    Question Consider the following employees table: Exercise Write a SQL query to retrieve the names of employees who earn…

社区洞察

其他会员也浏览了