部分數據內容如下:
括號劃分優先級
:找出上海本科的職位信息和北京碩士的職位信息
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 '%以上%'