SQL大厂笔试真题21
- avg(if语句)表示满足if条件的记录所占比例。
- concat( ,'%')将数值转换为字符串,并且添加%符号。
代码如下:
select department,
concat(round(avg(if(timestampdiff(minute,first_clockin,last_clockin)/60 > 9.5,1,0))*100,1),'%') as ratio from staff_tb join attendent_tb using(staff_id)
group by department
order by ratio desc
#牛客创作赏金赛#