Wednesday, March 5, 2014

SQL Part 1

Use TutorManagement
/* these are the basic
forms of the select statement
*/
Select * From Tutor
Select TutorLastName as [Last Name], TutorFirstName as [First Name], TutorEmail as Email
From Tutor

Select TutorLastName as [Last Name], TutorFirstName as [First Name], TutorEmail as Email
From Tutor
order by TutorLastName

Select TutorLastName as [Last Name], TutorFirstName as [First Name], TutorEmail as Email
From Tutor
order by TutorLastName desc

Select * From Tutor where tutorLastName='Brown'

--when searching for nulls use "is" or "is Not"
Select TutorLastName, TutorEmail from Tutor Where TutorEmail is not null

Select * from student where studentAge > 30
Select * from student where studentAge < 30
Select * from student where studentAge >= 30
Select * from student where studentAge <= 30

Select * From Student where StudentEmail Like '%hotmail%' or StudentEmail Like '%gmail%'

Select * from Session
Select Year(SessionDateKey) as [Year] From Session
Select Month(SessionDateKey) as [Month] From Session
Select Day(SessionDateKey) as [Day] from Session

Select cast(SessionTimeKey as Nvarchar(8)) from Session

Select DatePart(hour, SessiontimeKey) as [hour] from Session
Select DatePart(minute, SessionTimeKey) as [Minute] from Session

Select datediff(dd,GetDate(), '3/26/2014')
Select GetDate()
Select dateAdd(dd, 40, GetDate())

Select * From Student
Select Count(StudentKey) From Student
Select Count(StudentAge) From Student
Select Avg(StudentAge) From Student
Select max(StudentAge) From Student
Select Min (StudentAge) from Student
Select Sum(StudentAge) From Student

No comments:

Post a Comment