?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  
SELECT 
amortization_id,T.department_name,T.departments_id,D.`code`,D.id,N.id,
#REVERSE(T.department_name) AS S,
#LOCATE('-',REVERSE(T.department_name)) AS lent,
REVERSE(SUBSTRING(REVERSE(T.department_name),LOCATE('-',REVERSE(T.department_name))+1,100)) AS NEWCODE
FROM
tx_amortization_log T
LEFT JOIN departments D ON T.departments_id=D.id
LEFT JOIN departmentsNew N ON D.`code`=N.`code`
WHERE D.`code` IS NULL
 
 
SELECT 
amortization_id,department_name,T.departments_id,T.contract_id,share_accounted,
#REVERSE(T.department_name) AS S,
#LOCATE('-',REVERSE(T.department_name)) AS lent,
REVERSE(SUBSTRING(REVERSE(T.department_name),LOCATE('-',REVERSE(T.department_name))+1,100)) AS NEWCODE
FROM
tx_amortization_log T
LEFT JOIN departments D ON T.department_name=D.`code`
LEFT JOIN departmentsNew N ON D.`code`=N.`code`
WHERE 
#D.`code` IS NULL
contract_id=936
AND share_accounted=0.08
AND department_name LIKE '%B-BJ-318-613%'
 
 
SELECT 
amortization_id,department_name,T.departments_id
#,N.`code`,N.id,N.`name`
#,concat(N.`code`,'-',N.`name`)
FROM
tx_amortization_log T
LEFT JOIN departmentsNew N ON T.departments_id=N.`id`
 
#截取某字段最后一次出现位置之前的字符串
#REVERSE(left(REVERSE(T.department_name),LOCATE('-',REVERSE(T.department_name))-1))
 
  


---------------------------------------------------------------------------------------------
不忘初心 方得始终!

唯有志存高远,方能风行天下。

道之所存,虽千万人吾往矣! 情之所钟,虽千万里吾念矣~

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。