Day 5 - SQL Commands - YouTube
Day 5 - SQL Commands - YouTube
ORDER BY - Sort the Data, arrange the data in a sequence, either ascending order
(default) or in descending order (desc)
select f_nm from employee;
select f_nm from employee order by f_nm;
select f_nm from employee order by f_nm desc;
select f_nm from employee order by age;
select f_nm from employee order by age desc;
select * from employee order by age, salary; ---second level sort will happen
incase of a clash.
select id,f_nm,l_nm from employee order by id limit 1 offset 0; --- gives the
first record
select id,f_nm,l_nm from employee order by id limit 3 offset 3; --- beginning in
the 4th place it will give 3 records.
___________________________________________________________________________________
_________________________________
AGGREGATE FUNCTIONS - Sum, Avg, Min, Max, Count, Count Distinct ....
To get the total number of records - select count(*) from employee;
From how many locations are people joining - select count(location) from employee;
From how many distinct locations are people joining - select count(distinct
location) from employee;
To give an alias name to the column - select count(distinct location) as
num_of_locations from employee;
To get the number of people above 30 years - select count(f_nm) from employee where
age>30;
select count(f_nm) from employee where age>25 and age <35;
Identify the youngest employee - select min(age) from employee; gives the minimum
age, but to know who is the employee - select f_nm, l_nm from employee order by age
limit 1;