Structured Query Language (SQL) is de facto language for storing and retrieving structured data from a table. In this post, we will create a database organization and inside this database we create the following table.
Ecode | Name | Salary | Job | City |
---|---|---|---|---|
E1 | Ritu Singh | 50000 | Manager | Delhi |
E2 | Vikas Verma | 45000 | Executive | Jaipur |
E3 | Rajat Chaudhary | 30000 | Clerk | Delhi |
E4 | Reena Arora | 45000 | Manager | Banglore |
E5 | Prem Sharma | 50000 | Accountant | Kanpur |
Below SQL code creates a table and inserts 5 records into Employee table.
CREATE DATABASE if not exists organization; USE organization; CREATE TABLE Employee(Ecode VARCHAR(20), NAME VARCHAR(20),Salary INT, Job VARCHAR(20), City VARCHAR(20)); Insert Into Employee VALUES ('E1','Ritu Singh', 50000, 'Manager', 'Delhi'), ('E2','Vikas Verma', 45000, 'Executive', 'Jaipur'), ('E3','Rajat Chaudhary',30000,'Clerk','Delhi'),('E4', 'Reena Arora', 45000, 'Manager', 'Banglore'), ('E5', 'Prem Sharma', 50000,'Accountant', 'Kanpur') ;
Below are some SQL queries and their output are given.
——————————————————————————————————–
SELECT Ecode, NAME, MAX(Salary) FROM employee WHERE City='Delhi';
Output
E1 | Ritu Singh | 50,000 |
---|
——————————————————————————————————–
SELECT NAME, JOB FROM employee WHERE Salary BETWEEN 40000 and 50000;
NAME | JOB |
---|---|
Ritu Singh | Manager |
Vikas Verma | Executive |
Reena Arora | Manager |
Prem Sharma | Accountant |
——————————————————————————————————–
SELECT AVG(Salary) FROM employee WHERE Job IN('Manager','Clerk');
Output 41666.6667
——————————————————————————————————–
Select Sum(Salary) From Emplloyee Where Name Like '%a';
Output 140,000
——————————————————————————————————–