部分数据内容如下:
括号划分优先级
:找出上海本科的职位信息和北京硕士的职位信息
select * from DataAnalyst
where (city = '上海' and education= '本科')
or (city = '北京' and education = '硕士')
去重计数
:找出每个城市的职位数
select city,count(distinct positionId) from DataAnalyst
group by city
使用函数,字段运算,concat,round转换小数
:找出每个城市的职位数以及电子商务行业的职位数和占比
select city,
count(distinct positionId) as '职位数',
count(distinct if(industryField like '%电子商务%',positionId,null)) as '电商行业',
CONCAT(ROUND(count(distinct if(industryField like '%电子商务%',positionId,null)) *100/count(distinct positionId),2),'%') as '电商行业占比'
from mydf2
group by city
时间间隔
select date_add(date(now()) ,interval 1 day)
select date_add(date(now()) ,interval 1 WEEK)
可以改变1为负数,达到减法的目的,也能更改day为week、year等,进行其他时间间隔的运算。如果是求两个时间的间隔,则是datediff(date1,date2)或者timediff(time1,time2)。
文本清洗函数
MySQL支持left、right、mid等函数
locate函数查找位置
select left(salary,locate("K",salary)-1) as bottomSalary,
substr(salary,locate("-",salary)+1,length(salary)- locate("-",salary)-1) as topSalary,
city,positionId,workYear
from DataAnalyst
where salary not like '%以上%'