Consider the table Product given below:

Table: Product

P_ID

Name 

Category

Price

Discount

P01

Pen

Stationery

10

0.1

P02

Book

Stationery 

50

NULL

P03

Shirt

Clothing

500

0.2

P04

Jeans

Clothing

800

NULL

P05

Watch

Accessories

1000

0.15

Based on the given table, write SQL queries for the following:

(i) Increase the price by 20% of products whose discount is known.

Answer:

Answer by student

The SQL query to i ncrease the price by 20% of products whose discount is known is:

UPDATE Product SET Price = Price * 1.2 WHERE Discount IS NOT NULL;

Detailed answer by teachoo

-lock-

  • To increase the price by 20% of products whose discount is known, we need to use the UPDATE statement with the SET clause .
  • The SET clause specifies the new value for the column to be updated. In this case, we want to multiply the original price by 1.2 to get the increased price.
  • We also need to use the WHERE clause to filter the rows that match the condition . The condition is that the discount column should not be NULL, which means it has a known value. The SQL query for this is:

UPDATE Product SET Price = Price * 1.2 WHERE Discount IS NOT NULL; 

This query will modify the price column of the table Product for the rows where discount is not NULL and after the execution of the query, the table will look like this:

P_ID

Name

Category

Price

Discount

P01

Pen

Stationery

12

0.1

P02

Book

Stationery

50

NULL

P03

Shirt

Clothing

600

0.2

P04

Jeans

Clothing

800

NULL

P05

Watch

Accessories

1200

0.15

-endlock-

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.