簡體   English   中英

如何在sql中合並表的兩列?

[英]How can i merge two columns of a table in sql as a sentence?

我是數據庫編程的初學者。 我正在做作業,我得到了有關sql查詢的任務。 我的任務是在句子中合並表格(人)的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

dbfiddle上的演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM