Skip to main content

Command Palette

Search for a command to run...

Task: Calculated Columns Practice

Published
2 min read
M

As a former 3D Animator with more than 12 years of experience, I have always been fascinated by the intersection of technology and creativity. That's why I recently shifted my career towards MERN stack development and software engineering, where I have been serving since 2021.

With my background in 3D animation, I bring a unique perspective to software development, combining creativity and technical expertise to build innovative and visually engaging applications. I have a passion for learning and staying up-to-date with the latest technologies and best practices, and I enjoy collaborating with cross-functional teams to solve complex problems and create seamless user experiences.

In my current role as a MERN stack developer, I have been responsible for developing and implementing web applications using MongoDB, Express, React, and Node.js. I have also gained experience in Agile development methodologies, version control with Git, and cloud-based deployment using platforms like Heroku and AWS.

I am committed to delivering high-quality work that meets the needs of both clients and end-users, and I am always seeking new challenges and opportunities to grow both personally and professionally.

So far, we’ve learned how to create calculated columns using SQL.
Now it’s time to practice and make sure this concept is completely clear.

In this task, you’ll apply what you’ve learned by working with a new table.


The Scenario

You are given a table called phones.

This table contains the following columns:

  • name

  • manufacturer

  • price

  • units_sold

Each row represents a phone model and its sales information.


Your Goal

Your task is to write an SQL query that:

  1. Selects the name of every phone

  2. Calculates the total revenue for each phone

  3. Renames the calculated column as revenue


How Is Revenue Calculated?

Revenue is calculated using this formula:

revenue = price × units_sold

This calculation should be done inside the SQL query, not manually.


Visualizing the Problem

You can think of the data like this:

namemanufacturerpriceunits_sold

From this data, you want to generate a new calculated column:

| name | revenue |

Where:

  • revenue = price * units_sold

This calculated column does not exist in the table — it is created temporarily when you run the query.


What You Should Use

While writing your query, remember:

  • Use a calculated column

  • Use a math operator

  • Use AS to rename the calculated column


Try It Yourself ✍️

Go ahead and write the SQL query that fulfills the requirements above.

Take your time — this exercise is meant to strengthen your understanding of:

  • calculated columns

  • column aliases

  • basic math operations in SQL


Don’t Worry If You Get Stuck

If you feel stuck at any point:

  • that’s completely normal

  • this topic becomes clearer with practice