學習數據分析50天,我收穫到哪些?新人必看乾貨③mysql+描述統計篇

- 概念:
建議參考mysql基本語法
1、數據庫是數據存儲的集合,列存儲組織信息(各屬性),行存儲表中的明細記錄
2、主鍵唯一,不可爲空。
3、order by asc 升序,order by desc 降序
4、where … between …and…/in(…,…)/!=或<>/not in
where 可以配合and /or 一起用,注意處理邏輯
where 可以配合like模糊查詢
5、group by
一個小技巧,當group by A時,select A from 要有,否則會報錯。
常常後面如果是分組後要再篩選,用having。
6、null 值一般只用is nulll/not null來配合。
7、count if 嵌套。
例如:
count(if(id name like ‘%帥哥%’,id name,null)),count()不計null值。
8、locate(所查詢的字符串,查詢區域)類似find函數
例:left(salary,locate(‘k’,salary)-1),提取薪資中,字符‘k’左側的內容
9、substr(字符串,從哪裏開始,截取長度)
例:提取8k-15k
select salary,
left(salary,locate(‘k’,salary)-1),
substr(salary,locate(’-’,salary)+1,length(salary)-locate(’-’,salary)-1)
from table
10、在select …from 之間,有時候會用case when…then…end 來分類
例:

       select
        case when salary <= 500 then '1'

        when salary > 500 and salary <= 600  then '2'

        when salary > 600 and salary <= 800  then '3'

        when salary > 800 and salary <= 1000 then '4'

        else null end salary_class,

        count(*)

        from   table_a

11、連接字符串concat(char1,char2)
例: concat(concat( concat(姓名,工號),年齡),姓名)
12、join on (left join/inner join/right join),左並/取交/右並的關係。這塊常用
13、時間:now(),year(),month(),week(),date(精確到日期),date_format(區域,’%Y-%m), date_add(區域,interval _ day)下劃線中可以是正數,可以是負數,達到增減多少天的目的
14、update set
UPDATE zz SET 年齡 = year(now())-year(出生日期) where 工號>0

兩個注意點,
第一update ,在select * from 之前,更新完數據
第二where一定要加,不然會報錯~
15、INSERT INTO table_name (列1, 列2,…) VALUES (值1, 值2,…)
在這裏插入圖片描述
16、creat table
在這裏插入圖片描述
17、“+”
兩個都爲數值型,做加法
一個爲字符型,試圖轉化爲數值型,但‘join+90’還是會報錯
其中一個爲null,結果一定爲null

18、if null(有可能爲null的表達式,返回值)
19、查詢名字中第三個字符爲e,第5個爲a的職工工資
where name like’_ _ e _ a %’
between and 是包含臨界值的哦
20、upper 大寫,lower小寫
21、replace替換
select replace(select REPLACE(‘abcdefghabc’,‘abc’,‘xxx’)–輸入的字符串爲:abcdefghabc
結果爲:xxxdefghxxx
replace(原值區域,要替換的字符串,替換成)
22、truncate截斷
truncate(1.65,1)推出1.6,表示保留一位小數且沒有四捨五入哦


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章