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

Program 5

The document shows SQL commands to create and populate a database table with employee data. It inserts data for 7 employees, runs queries to select specific records by surname, city, gender and salary.

Uploaded by

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

Program 5

The document shows SQL commands to create and populate a database table with employee data. It inserts data for 7 employees, runs queries to select specific records by surname, city, gender and salary.

Uploaded by

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

mysql> create table persons

-> (P_Id int(5) primary key not null,Surname varchar(25),First_Name


varchar(30),Gender varchar(2),City varchar(30),Pincode varchar(20),Basic_Salary
int(30));
Query OK, 0 rows affected, 2 warnings (0.02 sec)

mysql> desc persons;


+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| P_Id | int | NO | PRI | NULL | |
| Surname | varchar(25) | YES | | NULL | |
| First_Name | varchar(30) | YES | | NULL | |
| Gender | varchar(2) | YES | | NULL | |
| City | varchar(30) | YES | | NULL | |
| Pincode | varchar(20) | YES | | NULL | |
| Basic_Salary | int | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
7 rows in set (0.02 sec)

mysql> insert into persons


-> values(1,'Sharma','Geeta','F','Udhamwara',182141,50000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into persons


-> values(2,'Singh','Surinder','M','Kupwara Nagar',183222,75000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into persons


-> values(3,'Jacob','Peter','M','Bhawani',185155,45000);
Query OK, 1 row affected (0.04 sec)

mysql> insert into persons


-> values(4,'Alvis','Thomas','M','Ahmed Nagar',300025,50000);
Query OK, 1 row affected (0.05 sec)

mysql> insert into persons


-> values(5,'Mohan','Garima','M','Nagar Colongatta',390026,33000);
Query OK, 1 row affected (0.01 sec)

mysql> insert into persons


-> values(6,'Azmi','Simi','F','New Delhi',110021,40000);
Query OK, 1 row affected (0.05 sec)

mysql> insert into persons


-> values(7,'Kaur','Manpreet','F','Udhamwara',182141,42000);
Query OK, 1 row affected (0.01 sec)

mysql> select * from persons;


+------+---------+------------+--------+------------------+---------+--------------
+
| P_Id | Surname | First_Name | Gender | City | Pincode | Basic_Salary
|
+------+---------+------------+--------+------------------+---------+--------------
+
| 1 | Sharma | Geeta | F | Udhamwara | 182141 | 50000
|
| 2 | Singh | Surinder | M | Kupwara Nagar | 183222 | 75000
|
| 3 | Jacob | Peter | M | Bhawani | 185155 | 45000
|
| 4 | Alvis | Thomas | M | Ahmed Nagar | 300025 | 50000
|
| 5 | Mohan | Garima | M | Nagar Colongatta | 390026 | 33000
|
| 6 | Azmi | Simi | F | New Delhi | 110021 | 40000
|
| 7 | Kaur | Manpreet | F | Udhamwara | 182141 | 42000
|
+------+---------+------------+--------+------------------+---------+--------------
+
7 rows in set (0.00 sec)

1. Display the Surname,Firstname and City of people residing in Udhamwara city.

mysql> select Surname,First_Name,City from persons where City='Udhamwara';


+---------+------------+-----------+
| Surname | First_Name | City |
+---------+------------+-----------+
| Sharma | Geeta | Udhamwara |
| Kaur | Manpreet | Udhamwara |
+---------+------------+-----------+
2 rows in set (0.00 sec)

2. Display the person IDs (PID),Cities and pincode of persons in descending order
of pincode.

mysql> select P_Id,City,Pincode from persons order by Pincode desc;


+------+------------------+---------+
| P_Id | City | Pincode |
+------+------------------+---------+
| 5 | Nagar Colongatta | 390026 |
| 4 | Ahmed Nagar | 300025 |
| 3 | Bhawani | 185155 |
| 2 | Kupwara Nagar | 183222 |
| 1 | Udhamwara | 182141 |
| 7 | Udhamwara | 182141 |
| 6 | New Delhi | 110021 |
+------+------------------+---------+
7 rows in set (0.00 sec)

3. Display the Firstname and cities of all the females getting basic salaries above
40000.

mysql> select First_Name,City from persons where Gender='F' and Basic_Salary>40000;


+------------+-----------+
| First_Name | City |
+------------+-----------+
| Geeta | Udhamwara |
| Manpreet | Udhamwara |
+------------+-----------+
2 rows in set (0.00 sec)

4. Display Firstnames and Basic Salaries of all the persons whose First Name starts
with 'G'.
mysql> select First_Name,Basic_Salary from persons where First_Name like 'G%';
+------------+--------------+
| First_Name | Basic_Salary |
+------------+--------------+
| Geeta | 50000 |
| Garima | 33000 |
+------------+--------------+
2 rows in set (0.00 sec)

5. Select Surname from persons where basic salary>=50000.

mysql> select Surname from persons where Basic_Salary>=50000;


+---------+
| Surname |
+---------+
| Sharma |
| Singh |
| Alvis |
+---------+
3 rows in set (0.00 sec)

6. Select Sum(basic_salary) from persons group by gender.

mysql> select Sum(Basic_Salary) from persons group by Gender;


+-------------------+
| Sum(Basic_Salary) |
+-------------------+
| 132000 |
| 203000 |
+-------------------+
2 rows in set (0.00 sec)

7. Select gender,count(*) from persons.

mysql> select Gender,count(*) from persons;


+--------+----------+
| Gender | count(*) |
+--------+----------+
| F | 7 |
+--------+----------+
1 row in set (0.00 sec)

You might also like