SQL Online Crash Course – Part 3 – Select Statement, Filter, Summarize and Group Data

Select * From Pupil;

 

Id    Name    DateBirth
1    Charly    2004-01-19 00:00:00.000
2    Sandy     2004-05-14 00:00:00.000
3    Jim       2003-12-01 00:00:00.000
Select * From Pupil
Where Id = 1;

 

Id    Name    DateBirth
1    Charly    2004-01-19 00:00:00.000
Select * From Pupil
Where DateBirth < '01.01.2004';

 

Id    Name    DateBirth
3    Jim       2003-12-01 00:00:00.000
Select *,
 Floor(DateDiff(day,DateBirth,GetDate())/365.242199) as Age
From Pupil;

 

Id    Name    DateBirth                   Age
1    Charly    2004-01-19 00:00:00.000    9
2    Sandy     2004-05-14 00:00:00.000    9
3    Jim       2003-12-01 00:00:00.000    10
Select Count(1) as Count From Pupil;

 

Count
3
Select Avg(FLOOR(DATEDIFF(day,DateBirth,GETDATE())/365.242199)) as AvgAge
From Pupil;

 

AvgAge
9.333333
Select Year(DateBirth) as Year, Count(1) as Count
From Pupil
Group By Year(DateBirth);

 

Year    Count
2003    1
2004    2