Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL-使用select语句更新表_Sql_Postgresql - Fatal编程技术网

PostgreSQL-使用select语句更新表

PostgreSQL-使用select语句更新表,sql,postgresql,Sql,Postgresql,我的问题是,把调查响应者名字的第一个字母和响应者姓氏的第一个字母连在一起,这样我就得到了这样一个结论:山姆·史密斯的结果是SS 我正在使用此查询来执行此操作并获得所需的结果: select concat(letterfirst, letterlast) as users from (select substring(first_name,1,1) as letterfirst, substring(last_name,1,1) as letterlast

我的问题是,把调查响应者名字的第一个字母和响应者姓氏的第一个字母连在一起,这样我就得到了这样一个结论:山姆·史密斯的结果是SS

我正在使用此查询来执行此操作并获得所需的结果:

select concat(letterfirst, letterlast) as users
from (select substring(first_name,1,1) as letterfirst, 
             substring(last_name,1,1) as letterlast
       from survey_responders) as user1

现在,我需要将结果传递到同一个表中的username列,即survey\u responders。我知道我必须使用update语句,但我似乎无法在使用带有update的select语句时绞尽脑汁

你把情况复杂化了:

update survey_responders
    set username = concat(left(first_name, 1), left(last_name, 1));

你把情况复杂化了:

update survey_responders
    set username = concat(left(first_name, 1), left(last_name, 1));

你看起来太容易了。啊!我花了两个小时想弄明白。谢谢!:)你看起来太容易了。啊!我花了两个小时想弄明白。谢谢!:)