平均数avg
select avg(employee.salary) as avg_salary from employee;
最大值max
select max(employee.salary) as max_salary from employee;
最小值min
select min(employee.salary) as min_salary from employee;
求和sum
select sum(employee.salary) as sum_salary from employee;
四舍五入round
select round(avg(employee.salary),2) as avg_salary from employee;
null判空
select isnull(dep_manager_gender),isnull(emp_count),ifnull(dep_manager,'放假啦') from company_manage;
select count(emp_count) from company_manage;
select count(*) from company_manage;
select count(distinct dep_count) from company_manage;
select count(age between 24 and 27) as age from employee where dep_name in('交付','苍盐海');
select count(*) as age from employee where (age between 24 and 27) and dep_name in('交付','苍盐海');
时间函数
select now() as now;
select current_date as now_date;
select current_time as now_time;
select current_timestamp as 'current_time';
select date(now()) as 'date',time(now()) as 'time';
select date(enter_time) as entry_date from employee;
select employee_name,enter_time,date(enter_time) as entry_date ,time(enter_time) as enter_time from employee;
select employee_name,enter_time,extract(hour from enter_time) as enter_hour from employee;
select employee_name,enter_time,extract(minute from enter_time) as enter_minute from employee;
select employee_name,enter_time,extract(second from enter_time) as enter_second from employee;
select employee_name,enter_time,extract(year from enter_time) as enter_year from employee;
select employee_name,enter_time,extract(month from enter_time) as enter_month from employee;
select employee_name,enter_time,extract(day from enter_time) as enter_day from employee;
select employee_name,date_format(enter_time,'%Y %m') as date_format from employee;
select employee_name,date_format(enter_time,'%Y %M') as date_format from employee;
select employee_name,date_format(enter_time,'%Y-%m-%d %H:%i:%S') as date_format from employee;
select enter_time,date_add(enter_time,interval 1 day) as delay_date from employee;
select enter_time,date_sub(enter_time,interval 1 day) as new_date from employee;
select enter_time,date_sub(enter_time,interval 2 day) as new_date from employee;
select timestampdiff(year,enter_time,'2022-09-13') as month_diff from employee;
select timestampdiff(month,enter_time,'2022-09-13') as month_diff from employee;
select timestampdiff(day,enter_time,'2022-09-13') as month_diff from employee;
select timestampdiff(hour,enter_time,'2022-09-13') as month_diff from employee;
select timestampdiff(minute,enter_time,'2022-09-13') as month_diff from employee;
select timestampdiff(second,enter_time,'2022-09-13') as month_diff from employee;