3

我的表格栏 -

在此处输入图像描述

我的预期输出将在列中更改-

Smith, Allen, Doyle, Dennis, Baker, Waker

这是我尝试过的,但没有用:( -

UPDATE TABLE `employee`
SET last_name = UCASE(LEFT(lower(last_name), 1))

UPDATE TABLE `employee`
SET last_name = ucase(lower(last_name),1)

也关注了这个链接 -资源

错误 -

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE `employee` SET last_name = UCASE(LEFT(lower(last_name), 1))' at line 1

让我知道我做错了什么以及如何解决。

4

3 回答 3

9

TABLE是保留关键字。它应该用反引号转义。

我认为TABLE不应该在您的查询中,(我认为这是一个错字

UPDATE employee
SET last_Name = CONCAT(UCASE(LEFT(last_Name, 1)), LCASE(SUBSTRING(last_Name, 2)))
于 2013-01-10T05:35:27.997 回答
2

试试这个可能有用

update `employee` 
set name=concat(left(upper(last_name),1),right(lower(last_name),length(last_name)-1));
于 2013-01-10T06:00:51.763 回答
0

如果这里有人正在寻找如何在包含两者的名称列中将名字和姓氏大写,这里有一个可能有用的片段:

 SELECT
    CONCAT( 
     UCASE(LEFT(substring_index(name, ' ',1),1)), 
     LCASE(SUBSTRING(substring_index(name, ' ',1),2)),
    ' ',
     UCASE(LEFT(substring_index(name, ' ',-1),1)), 
     LCASE(SUBSTRING(substring_index(name, ' ',-1),2))
    ) as name
FROM table
于 2014-04-23T02:36:41.170 回答