mysql 轉移字段 Mysql資料遷移與型別轉換

2021-10-17 17:47:47 字數 2834 閱讀 4812

條件語句case

case

when a.business_mark!='' then 2endas source_type,

條件語句 case else

case

when a.business_mark!='' then 2when a.rebate_id!='' then 1else0endas source_type,

case a.is_pay

when1 then 20when2 then 10endas recharge_state,

if語句

if(a.receive_time='',null,from_unixtime(a.receive_time)) as time_receive_user_pay,

如果receive_time為空,則取第二個值,否則就去第三個值

時間轉化 (1477984283 轉 y-m-d h:i:s)

from_unixtime(a.add_time) as time_publish_user_pay,

字段長度擷取 cast(a.price*0.93 as decimal(18,2))

case

when a.rebate_id!=' ' or a.business_mark !=' ' then cast(a.price*0.85 as decimal(18,2)) *100else cast(a.price*0.93 as decimal(18,2)) *100endas actual_pay_to_receiver_amount,

子查詢casewhen a.business_mark!='' then (select id from dl_business where mark=a.business_mark)

when a.rebate_id!=''then a.rebate_id

endas source_id,

條件為空查詢

select * from `dl_order` where business_mark is not null;

select* from `dl_order` where business_mark !='';

select * from `dl_order` where business_mark is null;

select max(length(desc)) from table order by length desc

兩表查詢

selecta.member_idasuser_id,

a.game_levelasdivision_id,

a.add_timeastime_create,

b.nameasdivision_namefromdl_member_attest a

left join dl_game_type b on a.game_level=b.id

limit0,10

三表查詢

select

a.idasuser_id,

c.idasdivision_id,

c.nameasdivision_name,

a.member_markashadchetman_sn,

case

when b.is_status= 1 then 0when b.is_status= 2 then 20when b.is_status= 3 then 10end

as hadchetman_state,

b.add_timeastime_createfromdl_member a

left join dl_member_attest b on a.id=b.member_id

inner join dl_game_type c on b.game_level=c.id

limit0,10

多個left join

selectif(a.pay_status =1,null,from_unixtime(a.add_time)) astime_publish_user_pay,if(a.receive_time='',null,from_unixtime(a.receive_time)) astime_receive_user_pay,

game_area.nameasgame_area_name,

last_division.nameaslast_season_division_name,

current_division.nameascurrent_division_name,

target_division.nameastarget_division_name,

member.mobileasreceive_user_name,0 asis_delete,1 asdata_versionfromdl_order a

left join dl_order_lol b on b.order_id=a.id

left join dl_game_type game_area on b.game_area=game_area.id

left join dl_game_type last_division on b.game_start_level=last_division.id

left join dl_game_type current_division on b.game_start_level=current_division.id

left join dl_game_type target_division on b.game_start_level=target_division.id

left join dl_member member on a.receive_member_id=member.id

order by a.id desc

limit0,100

mysql轉移老資料 mysql匯入匯出資料

window下 1.匯出整個資料庫 mysqldump u 使用者名稱 p 資料庫名 匯出的檔名 mysqldump u dbuser p dbname dbname.sql 2.匯出乙個表 mysqldump u 使用者名稱 p 資料庫名 表名 匯出的檔名 mysqldump u dbuser p...

mysql 字段 MySQL欄位型別詳解

mysql支援大量的列型別,它可以被分為3類 數字型別 日期和時間型別以及字串 字元 型別。本節首先給出可用型別的乙個概述,並且總結每個列型別的儲存需求,然後提供每個類中的型別性質的更詳細的描述。概述有意簡化,更詳細的說明應該考慮到有關特定列型別的附加資訊,例如你能為其指定值的允許格式。由mysql...

mysql表示字段 MySQL欄位型別

1 字段型別 字段型別分別為 數值型別 字串型別 日期時間型別。1.1 數值型別 數值型別分為整數型別和小數型別。整數型別為tinyint smallint mediumint int bigint。小數型別分為浮點型和定點型,有float double decimal。1.1.1 tinyint ...