我是psql的新手。 我有一张桌子'宠物'如下。
name | species | owner | gender | color
-------------+---------+--------------------+--------+---------------
Nagini | snake | Lord Voldemort | female | green
Hedwig | owl | Harry Potter | female | snow white
Scabbers | rat | Ron Weasley | male | unspecified
Pigwidgeon | owl | Ron Weasley | male | grey
Crookshanks | cat | Herminone Granger | male | ginger
Mrs Norris | cat | Argus Filch | female | dust-coloured
Trevor | toad | Neville Longbottom | male | brown
如何连接字符串并以它给出的方式输出字符串" Ron Weasley有X个宠物" (其中X = 2)?
对于X = 2部分我知道'select count(name) from pets where owner = 'Ron Weasley';'
但不确定如何在PSQL中连接和输出字符串。
答案 0 :(得分:0)
SELECT p.owner||' has ' count(p.name)||' pets' as conc_output
FROM pets p
WHERE owner = 'Ron Weasley';