如何将 table 中的 sql 的两列合并为一个句子?
How can i merge two columns of a table in sql as a sentence?
我是数据库编程的初学者。我正在做作业,我接到了一个关于 sql 查询的任务。我的任务是在一个句子中合并 table(人) 的 3 列(名字、姓氏、性别)。
例如:
"John Anderson is a male."
"Julia Smith is a female."
我写了以下查询:
SELECT first_name, last_name, ||' is a '|| sex ||'.'||
FROM person
LIMIT 10
我得到这个错误:
ERROR: Operator does not exist: text ||
LINE 1:select first_name, last_name, ||' is a '|| sex ||'.'||
^
HINT: No operator matches the specified name and argument type. You may have to add explicit type conversions.
如果有人能给我一个想法或解决方案,那对我来说会很棒。
你写 SELECT
表达式的方式有误,应该是
SELECT first_name || ' ' || last_name || ' is a ' || sex || '.'
FROM person
LIMIT 10
我是数据库编程的初学者。我正在做作业,我接到了一个关于 sql 查询的任务。我的任务是在一个句子中合并 table(人) 的 3 列(名字、姓氏、性别)。
例如:
"John Anderson is a male."
"Julia Smith is a female."
我写了以下查询:
SELECT first_name, last_name, ||' is a '|| sex ||'.'||
FROM person
LIMIT 10
我得到这个错误:
ERROR: Operator does not exist: text ||
LINE 1:select first_name, last_name, ||' is a '|| sex ||'.'||
^
HINT: No operator matches the specified name and argument type. You may have to add explicit type conversions.
如果有人能给我一个想法或解决方案,那对我来说会很棒。
你写 SELECT
表达式的方式有误,应该是
SELECT first_name || ' ' || last_name || ' is a ' || sex || '.'
FROM person
LIMIT 10