0% found this document useful (0 votes)
3 views

MySQL Queries

my sql series

Uploaded by

bomb78879
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

MySQL Queries

my sql series

Uploaded by

bomb78879
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MySQL Queries

1. Write SQL query to create the table Employee.


Create the following table: Employee
Field Name Datatype Constraint
Empid Integer Primary Key
Name Varchar(20) Not Null
Department Varchar(20) Not Null
Salary Integer
Gender Varchar(1)
DOJ Date

Solution:

CREATE TABLE Employee(


Emp Integer PRIMARY KEY,
Name varchar(20) NOT NULL,
Department varchar(20) NOT NULL,
Salary integer,
Gender varchar(1),
DOJ Date
);

2. Write SQL Query to insert any four records in the Employee table.
Insert the following records in the table created above.
Empid Name Department Salary Gender DOJ
1001 Aman Sales 40000 M 2010-11-21
1002 Neha Accounting 35000 F 2009-09-25
1003 Ravi Sales 45000 M 2015-05-02
1004 Sakshi Accounting 35000 F 2016-06-15

Solution:
INSERT INTO Employee VALUES(1001, ’Aman’, ’Sales’, 40000, ‘M’, ‘2010-11-21’);
INSERT INTO Employee VALUES(1002, ’Neha’, ’Accounting’, 35000, ‘F’, ‘2009-09-25’);
INSERT INTO Employee VALUES(1003, ’Ravi’, ’Sales’, 45000, ‘M’, ‘2015-05-02’);
INSERT INTO Employee VALUES(1004, ’Sakshi’, ’Accounting’, 35000, ‘F’, ‘2016-06-15’);
3. Write SQL Query to display all the records of all Female Employees.
Solution:
SELECT * FROM Employee WHERE Gender = ‘F’;
Output:

Empid Name Department Salary Gender DOJ

2 Neha Accounting 35000 F 2009-09-25

4 Sakshi Accounting 35000 F 2016-06-15

4. Write SQL Query to display name of employees in upper case who joined on “Wednesday”.
Solution:
SELECT UPPER(Name) FROM Employee WHERE DAYNAME(DOJ) = “Wednesday”;
Output:

UPPER(Name)

SAKSHI

5. Write SQL query to display the salary Department wise.


Solution:
SELECT SUM(Salary), Department FROM Employee group by Department;
Output:

SUM(Salary) Department

90000 Sales

70000 Accounting

You might also like