MySQL - JOIN基于CONVERT列到NUMERIC

时间:2014-04-25 01:31:55

标签: mysql sql join varchar

基本上,我尝试在进行连接时转换表字段。字段中的数字以0009897896,000239472938,00032423等开头。

我想做一个基于连接的转换,所以当我查询列时,它会显示没有前导0的数字,所以它们会显示为9897896,239472938,32423等等。

有人能帮助我做到这一点吗?我一直坚持这个问题:(

这是我到目前为止所做的事情......从另一个数据库加入:

SELECT l.loannumber AS '1 Loan number',
       fl.loan_num AS '2 Loan number',
       CASE
           WHEN loannumber<>fl.loan_num THEN "YES"
           ELSE "NO"
       END AS "issue?"
FROM loan l
LEFT JOIN cware_cms.file_lst fl ON (CONVERT(SUBSTRING_INDEX(l.LoanNumber, '-', -1), UNSIGNED INTEGER)) = (CONVERT(SUBSTRING_INDEX(fl.loan_num, '-', -1),UNSIGNED INTEGER))
LEFT JOIN cware_cms.case_lst cl ON cl.case_id =
  (SELECT MAX(cware_cms.file_case.case_id))
FROM cware_cms.file_case
INNER JOIN cware_cms.case_lst ON cware_cms.file_case.case_id = cware_cms.case_lst.case_id

1 个答案:

答案 0 :(得分:1)

我想你想要TRIM LEADING零。这样就可以了:

LEFT JOIN cware_cms.file_lst fl ON TRIM(LEADING '0' FROM l.loannumber) = TRIM(LEADING '0' FROM fl.loan_num)