1、mysql截取最后一個字符之前的數據
select
--截取斜杠之前的數據REVERSE(SUBSTR(REVERSE('SPNH-dfg-2012') ;
--截取斜杠后的數據 INSTR(REVERSE('SPNH-fg-2012'),'-')+1))
2、mysql獲取最后一個字符后的數據
select SUBSTRING_INDEX('SPNH-dfg-2012','-',-1)
3、mysql更新某個字段IP
update anchoremc_file_log set
address=replace(address,'192.168.1.29','111.175.140.46');update anchoremc_dailypaper_examine_case set
picture_url=replace(picture_url,'192.168.1.29','111.175.140.46')
- 實例插入語句:
INSERT INTO anchoremc_dailypaper_examine_case_new ( case_code, enterprise_name, enterprise_code, professional, select_device, device_name_wh, inspection_desc, handling_suggestions, problem_pro, inspection_date, picture_url, data_sources )
SELECTcase_code,enterprise_name,enterprise_code,professional,select_device,device_name_wh,inspection_desc,handling_suggestions,problem_pro,CONCAT(year,'-',moth,'-',day) inspection_date,'[]' picture_url,(CASE data_sourcesWHEN '' THEN 3WHEN NULL THEN 3WHEN '人工錄入' THEN 1else 0END ) data_sourcesFROManchoremc_dailypaper_examine_case_excelnew;SELECT * FROM anchoremc_dailypaper_examine_case_newwhere inspection_date = '2008-01-01';
5、更新案例編碼
update anchoremc_dailypaper_examine_case
set case_code_pre=REVERSE(SUBSTR(REVERSE(case_code) , INSTR(REVERSE(case_code),'-')+1)),case_code_end=SUBSTRING_INDEX(case_code,'-',-1) ,year_time= YEAR(inspection_date),moth_time=MONTH(inspection_date)WHEREyear_time IS NULL
6、更新鏈接
update anchoremc_file_log set address=replace(address,'192.168.1.29','111.175.140.46')
update anchoremc_dailypaper_examine_case set picture_url=replace(picture_url,'192.168.1.29','111.175.140.46')