Uploaded by Prateek Rathore

assignment 3

advertisement
Assignment
Table Used -Persons
select *from Persons
1)write few sample queries using regular expression
SELECT * FROM Persons
WHERE FirstName LIKE 'r%';
SELECT * FROM Persons
WHERE City LIKE '%e';
SELECT * FROM Persons
WHERE FirstName LIKE 'r%m';
SELECT * FROM Persons
WHERE City LIKE '[b]%';
SELECT * FROM Persons
WHERE City LIKE '[bpd]%';
SELECT * FROM Persons
WHERE FirstName LIKE '[a-i]%';
SELECT * FROM Persons
WHERE FirstName LIKE '[^A-C]%';
SELECT * FROM Persons
WHERE FirstName LIKE '[RH][AP]%';
2)How to read LAST 5 records from a table using a SQL query
SELECT TOP 5 * FROM Persons ORDER BY PersonID DESC
3)Query to fetch the unique records using GROUP BY function
SELECT City FROM Persons GROUP BY City;
4)Sql query to find maximum salary of each department
SELECT DEPT_ID, MAX(SALARY) FROM department GROUP BY DEPT_ID;
5)Sql query to find which departmet having more than 5 employees
select DEPT_ID,count(DEPT_ID) from department group by DEPT_ID having count(DEPT_ID)>5;
6)Sql query to find who joined last year and their salary greater than
3000
7)Sql query to find whose name start with 'T' and ends with 'S'
select * from table where name_column like 'T%S';
8)How to get domain name from maild
EX
1)gst@gmail.com --- output--- gmail
2)test1@yahoo.in --- output -- Yahoo
3)test@outlook.com --- output --- Outlook
SELECT ID,SUBSTRING ([mail], CHARINDEX( '@', [mail]) + 1,LEN([mail])) AS [Domain]FROM [email];
Download