开发者

sql query to get 2 values in a single field

开发者 https://www.devze.com 2023-03-12 13:45 出处:网络
Suppose I am开发者_JS百科 having table A with 3 fields Name, dob,age sara30-sep-199020 i need to get an output from select query as

Suppose I am开发者_JS百科 having table A with 3 fields Name, dob,age

sara 30-sep-1990 20

i need to get an output from select query as

sara,{30-sep-1990:20}

ie 2 values in a single field with braces seperated by colon


Concatenation depends on your DBMS :

MySQL: CONCAT()
Oracle: CONCAT(), ||
SQL Server: +

Example MySQL :

Select Name, CONCAT('{', dob, ':', age, '}')
From A


You don't show schema info (table, column names) or state which database you're using. For oracle:

select '{'||dob||':'||age||'}' from tablename;

For anything else see your database documentation. See the faq: https://stackoverflow.com/faq

0

精彩评论

暂无评论...
验证码 换一张
取 消