0% found this document useful (0 votes)
7 views7 pages

SQL Grade12 Program

Uploaded by

surabhisharmamca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

SQL Grade12 Program

Uploaded by

surabhisharmamca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Create a student table with the student id, name, and marks as attributes where the student id
is the primary key.

Ans.:

2.Insert the details of a new student in the above table.

Note plz insert atleast 5 values.

3.Delete the details of a student in the above table.


4. Use the select command to get the details of the students with marks more than 80.

Ans.:

select * from student where marks>80;

5.

Find the min, max, sum, and average of the marks in a student marks table.

Ans.:

select max(marks), min(marks), sum(marks) , avg(marks) from student;


6. Find the total number of customers from each country in the table (customer ID, customer
Name, country) using group by.

Ans.:

select country, count(customer_id) from customer group by country;

7. Write a SQL query to order the (student ID, marks) table in descending order of the marks.

Ans.:

select * from student order by marks desc;

8. Write a SQL query to display the marks without decimal places, display the reminder after
diving marks by 3 and display the square of marks.

Ans.:

select round(marks,0),mod(marks,3),pow(marks,2) from student;


9. Write a SQL query to display names into capital letters, small letters, display frist 3 letters of
name, display last 3 letters of name, display the position the letter A in name

Ans.:

select ucase(name), lcase(name), left(name,3),right(name,3), instr(name,'a') from student;

10Remove extra spaces from left, right and both sidesfrom the text - " Informatics Practices Class
XII "

Ans.:

select ltrim(" Informatics Practices Class XII ") "Left Spaces", rtim(" Informatics Practices Class XII ")
"Right Trim", trim(" Informatics Practices Class XII ");

11. Display today's date in "Date/Month/Year" format

Ans.:

select concat(date(now()), concat("/",concat(month(now()), concat("/",year(now())))));

12. Display dayname, monthname, day, dayname, day of month, day of year for today's date

Ans.: select dayname(now()), monthname(now()), day(now()), dayname(now()),


dayofmonth(now()), dayofyear(now());

13. write sql command to create two table sales and customer and insert values in it
Coachid Coachname Age Sport Dateofapp Pay Gender

1 Karan 35 Karate 27/03/19 10000 M

2 Ravina 34 Karate 20/01/20 12000 F

3 Kamal 34 Squash 19/02/20 20000 M

4 Tarun 33 Basketball 01/01/20 15000 M

5 Sumeru 36 Swimming 12/01/20 7500 M

6 Anjani 36 Swimming 24/02/20 8000 F

7 Shamima 37 Squash 20/02/20 22000 F

8 Soumya 30 Karate 22/02/20 11000 F


solution-- Create the Club table with proper integrity constraints
CREATE TABLE Club (
Coachid INT PRIMARY KEY,
Coachname VARCHAR(50) NOT NULL,
Age INT,
Sport VARCHAR(50) NOT NULL,
Dateofapp DATE,
Pay DECIMAL(10, 2),
Gender CHAR(1) CHECK (Gender IN ('M', 'F'))
);

-- Insert data into the Club table


INSERT INTO Club (Coachid, Coachname, Age, Sport, Dateofapp, Pay, Gender) VALUES
(1, 'Karan', 35, 'Karate', '2019-03-27', 10000, 'M'),
(2, 'Ravina', 34, 'Karate', '2020-01-20', 12000, 'F'),
(3, 'Kamal', 34, 'Squash', '2020-02-19', 20000, 'M'),
(4, 'Tarun', 33, 'Basketball', '2020-01-01', 15000, 'M'),
(5, 'Sumeru', 36, 'Swimming', '2020-01-12', 7500, 'M'),
(6, 'Anjani', 36, 'Swimming', '2020-02-24', 8000, 'F'),
(7, 'Shamima', 37, 'Squash', '2020-02-20', 22000, 'F');
14. Display information about coaches whose name start with K or pay is at least 1500 or both.
(Refer table ‘Club’ of Practical 13)

Solution: select *from club where Coachname like'k%' OR Pay>=1500;

15. Write a query to display report showing coachname, pay, age and bonus (15% of pay) for all
coaches. (Refer table ‘Club’ of Practical 13)

Solution SELECT

Coachname,

Pay,
Age,

Pay * 0.15 AS Bonus

FROM

Club;

16. write sql command to create two table sales and customer and insert values in it

Solution

Create the customer table:

CREATE TABLE customer (

customer_id INT PRIMARY KEY,

customer_name VARCHAR(100),

customer_email VARCHAR(100),

customer_phone int(20)

);

Create the sales table:

CREATE TABLE sales (

sale_id INT PRIMARY KEY,

sale_date DATE,

amount DECIMAL(10, 2),

customer_id INT,

FOREIGN KEY (customer_id) REFERENCES customer(customer_id)

);

Insert values into the customer table:

INSERT INTO customer (customer_id, customer_name, customer_email, customer_phone)

VALUES

(1, 'John Doe', '[email protected]', 5551234),

(2, 'Jane Smith', '[email protected]', 5555678),

(3, 'Alice Johnson', '[email protected]', 5558765);

. Insert values into the sales table:

INSERT INTO sales (sale_id, sale_date, amount, customer_id)

VALUES

(101, '2024-01-01', 100.00, 1),


(102, '2024-01-02', 150.50, 2),

(103, '2024-01-03', 200.75, 1),

(104, '2024-01-04', 250.25, 3);

17.perform left and right join on above table sales n customer

Solution

LEFT JOIN query:

SELECT sales.sale_id, sales.sale_date, sales.amount, customer.customer_name, customer.email

FROM sales

LEFT JOIN customer

ON sales.customer_id = customer.customer_id;

RIGHT JOIN query:

SELECT sales.sale_id, sales.sale_date, sales.amount, customer.customer_name, customer.email

FROM sales

RIGHT JOIN customer

ON sales.customer_id = customer.customer_id;

You might also like