WHAT WE LEARN
In this video, we discuss about:
- Select * vs Select specific column names
- Alias (AS)
- Computed columns
- ORDER BY
- Execution Order
Challenge question
Question 1:
Select only the
product_name,unit_price, andcategoryfrom the products table. Rename the columns toProduct,Price, andType.
Question 2
Show every employee’s full name as one column called
full_nameand their job title asposition. Only from the Engineering department.
Question 3
From the
productstable, show the product name, unit price, and calculate the price after a 15% discount. Call itdiscounted_price.
Question 4
From the
customerstable, showfirst_nameasFirst,last_nameasLast,cityasLocation, andsignup_dateasMember Since.
Question 5
Show every employee’s full name, salary, and their annual salary. Order by annual salary from highest to lowest.
Question 6
From
products, show the product name, unit price, cost price, and calculate the total cost per product. Call itline_total. Order by line_total descending.
Question 7
From
order_items, show theitem_id,quantity,unit_price, the total line value asline_total, and build a label column that readsitem_id: line total— for example5: 299.99. Call itsummary.
Question 8
From
employees, select full name, department, and monthly salary. Add a columntax_estimatewhich is 20% of salary. Order bytax_estimatedescending — using the alias, not the expression.
Question 9
A junior dev wrote SELECT * FROM products and pushed it to production. Write the corrected query that shows only product_id, product_name, category, unit_price, and stock_qty — keeping cost_price out of the result.
Question 10
From
order_items, showitem_id,unit_price,quantity, the line total, the line total including 20% VAT asline_total_vat, and the VAT amount alone asvat_amount.
Question 11
Write a single SELECT from
employeesthat shows: full name, department, job title, annual salary, annual salary after a 10% raise asnew_salary, and the raise amount alone asraise_amount. Order byraise_amountdescending, NULLs last.
Submit your answer on the comment box.