-6

Write a SELECT statement that returns these columns from the Vendors table:

  • The vendor_name column
  • The vendor_name column in all capital letters
  • The vendor_phone column
  • The last four digits of each phone number

When you get that working right, add the columns that follow to the result set. This is more difficult because these columns require the use of functions within functions.

  • The second word in each vendor name if there is one; otherwise, blanks
  • The vendor_phone column with the parts of the number separated by dots as in 555.555.5555

this is what i have tried so far:

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;
4

2 回答 2

0

尝试这个..

SELECT vendor_name, CONVERT(VARCHAR(50), UPPER(vendor_name)),SUBSTRING(vendor_phone,  LEN(vendor_phone)-3 ,4) FROM Vendors 
于 2013-10-09T04:45:26.500 回答
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

于 2020-10-06T09:10:19.360 回答