使用mysql進行資料降維

2021-09-28 16:22:04 字數 1443 閱讀 1846

樣例判斷匹配

select

t.name,

(case t.***

when 1 then

『男』when 0 then

『女』else

『未知』

end) 性別

from

t_customer t

指定檢視某個庫的某個表的所有字段

select distinct column_name from information_schema.columns where table_name = 『tablename』 and table_schema=『cona_web』 and table_name not like 『vw%』;

按某個值分組,如果並制定分組排名的位數,不足的前面補零

select b.* , lpad(b.rank,2,0) from

(select a.*, if(@p=floor_id,@r:=@r+1,@r:=1) as rank ,

@p:=floor_id

from fhfq a ,(select @p:=null,@r:=0)r

order by a.floor_id

) b《mysql中相較於hive排名函式上使用比較複雜,有更好的方法希望各位大佬指導》

將list按著#進行切分,然後與另外一張表進行關聯之後進行聚合

行轉列 列轉行

select

c.,group_concat(d.course_name) as course_id_list

from

(select

a.,substring_index(

substring_index(

a.course_id_list,

『#』,

help_topic_id + 1

),『#』,

- 1) course_id

from

cona_web.train_plana

inner join mysql.help_topicb

on b.help_topic_id < (

length(a.course_id_list) - length(

replace(a.course_id_list, 『#』, 『』)

) + 1

)) c

left join train_course d

on c.course_id

group by c.id

最後分享幾個小技巧

create table ***

select * from bbb;

show create table ***;

即可得到建表語句,自己根據建表語句微調之後,省去大量建表的工作

使用MYSQL進行資料庫備份

使用mysql進行資料庫備份,又很正規的資料庫備份方法,同其他的資料庫伺服器有相同的概念,但有沒有想過,mysql會有更簡捷的使用檔案目錄的備份方法,而且又快有好。一 資料備份捷徑 因為這個方法沒有得到官方正式文件的驗證,我們暫稱為試驗吧。目的 備份hosta主機中乙個mysql資料庫testa,並...

如何使用Python與Mysql進行資料互動

自己的夢想需要你自己去實現 python 在mysql的官網獲取python與mysql的互動手冊mysql官方手冊 pythontodatabase.py import mysql.connector cnx mysql.connector.connect user root password 6...

使用pca進行座標系轉換 降維

pca是一種常用的資料降維的方法,而其中的降維的步驟就是 如果我們不選擇這個步驟,那麼就不會進行降維了,反而會進行座標系的轉換。新座標的優化目的 使得座標軸正交,並且沿著這些座標方向的資料的方差最大。clear clc close all mul 1 2 sigma 1 0.81 0.81 1 da...