/*viết thủ tục thực hiên các yêu cầu sau, sau đó dùng thủ tục thực thi 1 trường hợp cụ thể (tham số
tùy chọn)*/--1.tính lương của 1 mã nhân viên (tham số)createproc calEmplyeeSalary(@idchar(3))asbeginselect HONV,TENLOT, TENNV, LUONG from NHANVIEN
where MANV =@idendexec calEmplyeeSalary '009'dropproc calEmplyeeSalary
--2.xem thông tin của 1 mã nhân viên (tham số)createproc displayEmployeeInfo(@idchar(3))asbeginselect*from NHANVIEN
where MANV =@idendexec displayEmployeeInfo '003'--3.nv có lương của cao nhấtcreateproc highestEmployeeSalary asbeginselect HONV,TENLOT, TENNV, LUONG from NHANVIEN
where LUONG >=(SELECTMAX(LUONG)from NHANVIEN)endexec highestEmployeeSalary
--4.nhân viên có lương cao nhất của 1 tên phòng (tham số)createproc highestEmployeeSalaryInRoom(@tenphong nvarchar(20))asbeginselect HONV,TENLOT, TENNV, LUONG, TENPHG from NHANVIEN, PHONGBAN
where PHG = MAPHG and TENPHG =@tenphonggroupby HONV,TENLOT, TENNV, LUONG, TENPHG
having LUONG >=(selectMAX(LUONG)from NHANVIEN, PHONGBAN
where PHG = MAPHG and TENPHG =@tenphong)endselect NHANVIEN.*from NHANVIEN, PHONGBAN
where PHG = MAPHG and TENPHG = N'Nghiên cứu 'exec highestEmployeeSalaryInRoom N'Nghiên cứu 'dropproc highestEmployeeSalaryInRoom
--5.2 nhân viên có lương cao nhấtcreateproc twoHighestEmployeeSalary asbeginselecttop2 HONV,TENLOT, TENNV, LUONG from NHANVIEN
orderby LUONG descendexec highestEmployeeSalary
--6.20% nhân viên có lương cao nhấtcreateproc highestEmployeeSalaryByPercent(@percenttinyint)asbeginselecttop(@percent)percent HONV,TENLOT, TENNV, LUONG from NHANVIEN
orderby LUONG descendexec highestEmployeeSalaryByPercent 20--7.phòng ban có nhiều nv nhấtcreateproc roomHasMaxEmployee asbeginselectCOUNT(MANV), TENPHG from NHANVIEN,PHONGBAN
where PHG = MAPHG
groupby TENPHG
havingCOUNT(MANV)>=all(selectCOUNT(MANV)from NHANVIEN,PHONGBAN
where PHG = MAPHG
groupby TENPHG)end--8.2 phòng ban có nhiều nhân viên nhấtcreateproc twoRoomHasMaxEmployee asbeginselecttop2COUNT(MANV)as fuck, TENPHG from NHANVIEN,PHONGBAN
where PHG = MAPHG
groupby TENPHG
orderby fuck descendexec twoRoomHasMaxEmployee
--9.nv có địa chỉ ở tphcmcreateproc showEmployeeByAddress(@address nvarchar(50))asbeginselect HONV,TENLOT, TENNV, DCHI from NHANVIEN
where DCHI like@addressendexec showEmployeeByAddress N'%Tp HCM%'--10. nv làm việc cho 1 tên đề áncreateproc showEmployeeByProjectName(@projectName nvarchar(30))asbeginselect HONV,TENLOT, TENNV,TENDA from NHANVIEN,DEAN
where PHG = PHONG and TENDA =@projectNameendexec showEmployeeByProjectName N'Cáp quang '