Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

(iii) Display the name, address, and phone of customers who have placed orders in the month of June or July.

Answer:

Answer by student

SELECT CName, Address, Phone FROM CUSTOMER, ORDER WHERE CUSTOMER.CID = ORDER.CID AND (Date LIKE ‘%-06-%’ OR Date LIKE ‘%-07-%’); 

Detailed answer by teachoo

  • To display the name, address, and phone of customers who have placed orders in the month of June or July, we need to use the SELECT statement in SQL. In this case, we want to select the CName, Address and Phone columns from the CUSTOMER table.
  • We also need to join the CUSTOMER table with the ORDER table based on the CID column.
  • We also need to specify the condition that the Date column of the ORDER table contains either 06 or 07 as the month part.
  • We use the WHERE clause to specify these conditions.
  • We also use parentheses to group multiple conditions and use OR operator to combine them .
  • We also use LIKE operator and wildcard characters (%) to match a pattern in a string value .

So, we write:

SELECT CName, Address, Phone FROM CUSTOMER, ORDER WHERE CUSTOMER.CID = ORDER.CID AND (Date LIKE '%-06-%' OR Date LIKE '%-07-%');

  • Here, % represents any sequence of characters in SQL. So, Date LIKE ‘%-06-%’ means any date that has -06- as a substring.

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.