编写一个SELECT语句,从Vendors表中返回这些列:
如果能够正常工作,请将后面的列添加到结果集中。这更加困难,因为这些列需要在函数内使用函数。
这是我到目前为止所尝试的:
select vendor_name, UPPER(vendor_name) AS VENDOR_NAME_UPPER,
vendor_phone, SUBSTR(vendor_phone, 11, 4),
Replace
(replace
(replace(vendor_phone, ') ', '.')
, '(', '')
, '-','.') AS vendor_phone_dot,
SUBSTR(vendor_name, (INSTR(vendor_name, ' ') + 1)) AS Second_Word
from vendors;
答案 0 :(得分:0)
试试这个..
SELECT vendor_name, CONVERT(VARCHAR(50), UPPER(vendor_name)),SUBSTRING(vendor_phone, LEN(vendor_phone)-3 ,4) FROM Vendors
答案 1 :(得分:0)
SELECT vendor_name,
UPPER(vendor_name),
vendor_phone,
RIGHT(vendor_phone, 4),
REPLACE(REPLACE(REPLACE(RIGHT(vendor_phone, 13),')','.')," ",""),"-","."),
CASE vendor_name
WHEN (LOCATE(' ', vendor_name) = 0) THEN (SUBSTRING_INDEX(SUBSTRING(vendor_name, LOCATE(' ', vendor_name) + 1),' ', 1))
ELSE ''
END
FROM ap.vendors;
Murach的MySQL(第3版),第9章,练习3