practical program sql (2)
practical program sql (2)
Program : Creating, inserting values, updating and display a table in many forms
using SQL Queries
Aim:
A: Creating a table:
mysql> create table student(sid int(5), sname char(20), gender char(7), city
char(30), phonenum int(10));
Query OK, 0 rows affected (0.08 sec)
mysql> create table marks(sid int(5), Computer int, Physics int, Chemistry int,
Biology int);
Query OK, 0 rows affected (0.08 sec)
F: Aggregate Functions
Customer_I
Customer_Name Country
D
111 Latha Australia
112 Saranya India
113 Sathya Brazil
114 Karthick India
115 Shnajay Australia
116 Triya Australia
117 Sugachini Brazil
118 Shambavi China
119 Shanjay India
120 Triya India
Country count(*)
Australia 3
India 4
Brazil 2
China 1
Table Structure (Students)
Queries
UPDATE Students
SET Grade = '12th'
WHERE StudentID = 2; -- Updating Jane Smith's grade
Queries
sql
SELECT * FROM Employees;
sql
sql
sql
sql
sql
UPDATE Employees
SET Salary = 75000.00
WHERE EmployeeID = 4; -- Updating Emily Davis' salary
sql
sql
sql
sql
sql
sql
sql
sql
sql
SELECT
CASE
WHEN Salary < 60000 THEN 'Low Salary'
WHEN Salary BETWEEN 60000 AND 70000 THEN 'Mid Salary'
ELSE 'High Salary'
END AS SalaryRange,
COUNT(*) AS EmployeeCount
FROM Employees
GROUP BY SalaryRange;
sql
SELECT * FROM Employees
WHERE Phone IS NULL;
sql
sql
20. Get employees who have been with the company for more than 2 years
sql
,,Consider the following table and Write SQL queries for (I) to (IV)
TABLE : HOSPITAL
No Name Age Department Datofadm Charges Sex
1 Sandeep 65 Surgery 23/02/98 300 M
2 Ravina 24 Orthopedic 20/01/98 200 F
3 Karan 45 Orthopedic 19/02/98 200 M
4 Tarun 12 Surgery 01/01/98 300 M
5 Zubin 36 ENT 12/02/98 250 M
6 Ketaki 16 ENT 24/02/98 300 F
7 Ankita 29 Cardiology 20/02/98 800 F
8 Zareen 45 Gynecology 22/02/98 300 F
9 Kush 19 Cardiology 13/01/98 800 M
10 Shaliya 31 Nuclear Medicine 19/02/98 400 M
(3) To list names of all patients with their date of admission in ascending order.