Skip to content
Worked Examples · Example 1.2

Q.Using the SALE table of the CARSHOWROOM database:

(a) Add a new column Commission to the SALE table. The column Commission should have a total length of 7 with 2 decimal places.
(b) Calculate the commission for sales agents as 12 per cent of the SalePrice, insert the values into the newly added Commission column, and then display the records of the SALE table where Commission > 73000.
(c) Display InvoiceNo, SalePrice and Commission such that the Commission value is rounded off to 0 decimal places.
Telangana TsbieTextbookSubjective· 4mImportance★★★★★
8% · 3/40 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Add a Commission column to the real SALE table, fill it with 12% of SalePrice, then filter and round it — using MySQL's ADD(...), UPDATE ... SET, WHERE, and ROUND().

This is a code/query task on the SALE table of the CARSHOWROOM database — the same six rows used throughout this chapter:

InvoiceNoCarIdCustIdSaleDatePaymentModeEmpIDSalePrice
I00001D001C00012019-01-24Credit CardE004613247.00
I00002S001C00022018-12-12OnlineE001590321.00
I00003S002C00042019-01-25ChequeE010604000.00
I00004D002C00012018-10-15Bank FinanceE007659982.00
I00005E001C00032018-12-20Credit CardE002369310.00
I00006S002C00022019-01-30Bank FinanceE007620214.00

(a) ALTER TABLE ... ADD(column type) creates the new column:

ALTER TABLE SALE ADD(Commission Numeric(7,2));

Numeric(7,2) gives a total of 7 digits with 2 after the decimal point — enough for commissions up to 99999.99.

(b) Fill it with 12% of SalePrice, then filter:

UPDATE SALE SET Commission=12/100*SalePrice;
SELECT * FROM SALE WHERE Commission > 73000;

12/100*SalePrice computes 12% of each row's SalePrice. Checking every row: I00001 → 73589.64, I00002 → 70838.52, I00003 → 72480.00, I00004 → 79197.84, I00005 → 44317.20, I00006 → 74425.68. Only three exceed 73000:

InvoiceNoCarIdCustIdSaleDatePaymentModeEmpIDSalePriceCommission
I00001D001C00012019-01-24Credit CardE004613247.0073589.64
I00004D002C00012018-10-15Bank FinanceE007659982.0079197.84
I00006S002C00022019-01-30Bank FinanceE007620214.0074425.68
Watch out

I00002's commission (70838.52) is close to 73000 but still below it — don't round early and accidentally include it. Compare the full-precision value against the threshold. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.